multithreading

QSerialPort in QThread run bytesAvailable is zero

心不动则不痛 提交于 2020-01-16 18:18:39
问题 Have a simple Qt app. Gui thread, creates Dev thread it creates (in its run()) Read thread. Dev and Read threads are my classes inherited from QThread. The Read thread should read data from COM port continuously. An approximate view of Read run is following. read::run() { sp2->clear(); while (DO_EXEC) { if (DO_WRITE) { // write data to port } usleep(500); ba = sp2->bytesAvailable(); if (ba > 0) { int a = sp2->read(&BUF[BUF_END], ba); // process data emit sgnl(sendeddata); } } } To start it I

wait() and notify() method , always IllegalMonitorStateException is happen and tell me current Thread is not Owner Why?

好久不见. 提交于 2020-01-16 16:08:23
问题 package pkg_1; public class ExpOnWaitMethod extends Thread { static Double x = new Double(20); public static void main(String[] args) { ExpOnWaitMethod T1 = new ExpOnWaitMethod(); ExpOnWaitMethod T2 = new ExpOnWaitMethod(); T1.start(); T2.start(); } public void run() { Mag mag = new Mag(); synchronized (x) { try { for (int i = 1; i < 10; i++) { mag.nop(Thread.currentThread()); x = i * 2.0; } } catch (InterruptedException e) { e.printStackTrace(); } } } } class Mag { char ccc = 'A'; public

wait() and notify() method , always IllegalMonitorStateException is happen and tell me current Thread is not Owner Why?

核能气质少年 提交于 2020-01-16 16:08:06
问题 package pkg_1; public class ExpOnWaitMethod extends Thread { static Double x = new Double(20); public static void main(String[] args) { ExpOnWaitMethod T1 = new ExpOnWaitMethod(); ExpOnWaitMethod T2 = new ExpOnWaitMethod(); T1.start(); T2.start(); } public void run() { Mag mag = new Mag(); synchronized (x) { try { for (int i = 1; i < 10; i++) { mag.nop(Thread.currentThread()); x = i * 2.0; } } catch (InterruptedException e) { e.printStackTrace(); } } } } class Mag { char ccc = 'A'; public

Use a thread to wait until the user has picked a file

蓝咒 提交于 2020-01-16 14:35:06
问题 I have a mainClass in Java, that starts a GUI in swing. I ask the user to open a file using a JFileChooser. I want the main to wait until the user has finished picking the file and then continue with the rest of the code in main. How do I do this using threads? Thanks in advance. Here is the skeleton code: public class MainClass { public static void main(String[] args) { GUI gui= new GUI(); //wait for user input here //Continue with code System.out.println("User has picked a file"); } } GUI

How to use threads in python

岁酱吖の 提交于 2020-01-16 14:34:07
问题 I want to use it for reading values in 17770 files and to add all of them at the end to one dictionary object. I have a machine with 8 cores. This is the code def run_item_preprocess (): scores = {}; for i in range(1,17771): filename1 = "x_" + str(i) + ".txt"; lines1 = open(filename1).readlines(); Item1 = {}; for line in lines1: tokens = line.split(','); Item1[int(tokens[1])] = int(tokens[2]); for j in range(1,17771): if j == i: continue; filename2 = "x_" + str(i) + ".txt"; lines2 = open

How to manage mainwindow from QThread in Qt

半城伤御伤魂 提交于 2020-01-16 14:33:41
问题 My problem is the following one: I have 2 classes (mainwindow and mythread), I run the thread from the mainwindow and I would like to display some QLabel of my mainwindow from mythread : mythread.cpp : void mythread::run() { while(1) { this->read(); } } void mythread::read() { RF_Power_Control(&MonLecteur, TRUE, 0); status = ISO14443_3_A_PollCard(&MonLecteur, atq, sak, uid, &uid_len); if (status != 0){ //display Qlabel in mainwindow } } mainwindow.cpp : _thread = new mythread(); _thread-

Python threading - How to repeatedly execute a function in a separate thread?

拈花ヽ惹草 提交于 2020-01-16 14:08:31
问题 I have this code: import threading def printit(): print ("Hello, World!") threading.Timer(1.0, printit).start() threading.Timer(1.0, printit).start() I am trying to have "Hello, World!" printed every second, however when I run the code nothing happens, the process is just kept alive. I have read posts where exactly this code worked for people. I am very confused by how hard it is to set a proper interval in python, since I'm used to JavaScript. I feel like I'm missing something. Help is

Event Text Postback from Multithreaded Class to Windows ActiveForm

半腔热情 提交于 2020-01-16 13:47:21
问题 So I have an interesting problem (to me anyway). I am writting an application that runs a scan and posts information from a class back to a Windows Form. Right now I am creating an instance of a form, accessing the ActiveForm, then posting some text to a public function in that form. Scan.cs // Sets the text of scan history in the ui private void SetScanHistory(string text) { MyWinForm1 form = (MyWinForm1)MyWinForm1.ActiveForm; if (form != null) { form.SetText(text); } } MyWinForm1.cs // Sets

PyQt4, Generating multiple Instances of the same widget?

不羁岁月 提交于 2020-01-16 13:21:52
问题 I am creating a PyQt4 gui that allows the user in a qmainwindow to input some initial parameters and then click a start button to begin a program. When they click the start button, a new window that displays the parameters appears, and the program begins. I would like the user to be able to initiate multiple instances of the program. However, when the parameters are changed in the qmainwindow and the start button is clicked a second time, the first program window disappears. Is there a way to

InvalidOperationException when multithreading in WPF

牧云@^-^@ 提交于 2020-01-16 13:15:13
问题 So I'm working on my first multithreaded WPF app. Please bear in mind I have little to no understanding of how to implement multithreading - I've done it in a few apps and always work off the existing code. This is my first attempt at it in WPF which is apparently quite different to Windows Forms... So basically I'm working on this example which oddly enough doesn't mention that you have to instantiate a new thread and start it - I guess the author felt that was self evident even to newbies