PDA

View Full Version : GUI and non-GUI thread problem



dimaz
18th September 2008, 20:18
I have GUI thread and non-gui thread, that monitors status of the some device.

When the device state changed non-gui thread executes the function that changes some items in GUI, but I get errors and incorrect work of GUI.

QPixmap: It is not safe to use pixmaps outside the GUI thread
QPixmap: It is not safe to use pixmaps outside the GUI thread
QPixmap: It is not safe to use pixmaps outside the GUI thread
QCoreApplication::sendPostedEvents: Cannot send posted events for objects in another thread
QCoreApplication::sendPostedEvents: Cannot send posted events for objects in another thread


What can I do to make this work properly?

caduel
18th September 2008, 20:29
You must not use any gui classes etc from the non-gui thread (i.e. not from any threads you created).

Use (queued) signals or custom events to "signal" the gui thread about state changes in your thread and have the gui thread update the gui accordingly.

(Hint: search this forum for "thread" and "gui". Should give many useful threads. E.g. today's "how to use prograssbar in a thread".)

HTH

dimaz
18th September 2008, 21:09
I've try to use signals, but got error:

in class:
signals:
void canceled();

in constructor
connect(this, SIGNAL(canceled()), kiosk, SLOT(cancel()));

in run()
emit canceled();

and got
undefined reference to `PrinterStatusThread::canceled()'

caduel
18th September 2008, 21:25
Probably you forgot to add the Q_OBJECT line to your class decl or to add the header to your .pro files HEADERS section (and thus moc did not get run on your class).