[Qt-interest] boost::signals2 with Q_SLOTS - QPixmap not safe outside GUI thread?

Malyushytsky, Alex alex at wai.com
Wed Sep 23 23:17:11 CEST 2009


What is inside connectOnDeviceParameterChanged?

You should use Qt::QueuedConnection ( or sometimes Qt::BlockingQueuedConnection ) ( in connect call) to communicate with gui thread,
but default Qt::AutoConnection flag should do the job , cause

"If the signal is emitted from the thread in which the receiving object lives, the slot is invoked directly, as with Qt::DirectConnection; otherwise the signal is queued, as with Qt::QueuedConnection."

So  you should check if object emitting signal ids in other thread and/or type of connection you specified.

Alex



-----Original Message-----
From: qt-interest-bounces at trolltech.com [mailto:qt-interest-bounces at trolltech.com] On Behalf Of Ed Sutton
Sent: Wednesday, September 23, 2009 11:19 AM
To: qt-interest at trolltech.com
Subject: [Qt-interest] boost::signals2 with Q_SLOTS - QPixmap not safe outside GUI thread?

I understand the concept of single-threaded GUI and realize this
message is bad.

Here is what I am doing:

1 - My worker thread lib implements a boost::signal2.
2 - In my QT GUI project I have CONFIG += no_keywords and I replaced
the related keywords with the equivalent Q_ macros.
2 - My QMainWindow slot connects to the signal and receives the data
as demonstrated when I output the data to cout.
3 - Attempts to update statusBar()->showMessage() result in:
"QPixmap: It is not safe to use pixmaps outside the GUI thread"

How can I properly connect my worker thread using boost::signals2 to
the QT GUI thread?

Thanks in advance for any tips or direction,

-Ed

// Binding the worker thread signal to the MainWindow GUI handler
m_pMyWorkerThreadLib->connectOnDeviceParameterChanged(boost::bind(&MainWindow::onDeviceParameterChangedHandler,
this, _1));

class MainWindow : public QMainWindow
{

public Q_SLOTS:

// The GUI slot signalled   from the worker
void onDeviceParameterChangedHandler( Device* pDevice)
{
   // Beware: QPixmap: It is not safe to use pixmaps outside the GUI thread
   statusBar()->showMessage(tr("onDeviceParameterChangedHandler"));
}


}
_______________________________________________
Qt-interest mailing list
Qt-interest at trolltech.com
http://lists.trolltech.com/mailman/listinfo/qt-interest


---------------------------------------------------------------------------------------------------
Weidlinger Associates, Inc. made the following annotations.

"This message and any attachments are solely for the intended recipient and may contain confidential or privileged information. If you are not the intended recipient, any disclosure, copying, use, or distribution of the information included in this message and any attachments is prohibited. If you have received this communication in error, please notify us by reply e-mail and immediately and permanently delete this message and any attachments. Thank you."

"Please consider our environment before printing this email."




More information about the Qt-interest-old mailing list