PDA

View Full Version : Producuer Consumers GUI app with circular buffer



splurgeola
29th December 2010, 16:42
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.

tbscope
29th December 2010, 20:01
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:

producerObject->moverToThread(producerThread);

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.