Hello, I'm trying to write GUI multithreading application on PyQt, but with no luck . Can anyone could write sample code how to make produce and consumer threads work with GUI.
Thanks.
Hello, I'm trying to write GUI multithreading application on PyQt, but with no luck . Can anyone could write sample code how to make produce and consumer threads work with GUI.
Thanks.
Create a producer class, call it "Producer" and inherit it from QObject.
Implement it.
Create a consumer class, call it "Consumer" and inherit it from QObject
Implement it.
Create an object based on the the Producer class, call it "producerObject".
Create one or more objects based on the Consumer class. In case of one consumer, call it "consumerObject".
Establish the communication between the objects, the easiest way is to use signals and slots I guess.
Create a QThread object for each Producer or Consumer object.
Example: producerThread and consumerThread.
Move the producerObject to the producerThread (see QObject::moveToThread)
Do the same with the consumerObject.
In c++, assuming both producerObject and producerThread are pointers:
Qt Code:
producerObject->moverToThread(producerThread);To copy to clipboard, switch view to plain text mode
Start the producerThread and the consumerThread.
Use the signals and slots to do something useful. Both the producer and consumer will run in separate threads and the gui will be run in the main thread.
Bookmarks