[Qt-interest] QProgresBar + QThread = It is not safe to use pixmaps outside the GUI thread
Malyushytsky, Alex
alex at wai.com
Fri Aug 14 22:56:51 CEST 2009
At the best of my knowledge.
QProgressBar is a widget, it is not safe to draw anything in QWidget from the non - gui thread.
And this is what you do when you call slots directly.
You might connect the QObject's signals (the one which belongs to your QThread, create one if you don't have any) to the appropriate QProgressBar slots using
Qt::QueuedConnection (Qt::AutoConnection should work too, cause if objects belong to different threads Qt::QueuedConnection will be used).
Emit signals when you need to update QProgressBar.
Or you might use PostEvents instead to notify QProgressBar. First approach seems easier.
I have not done this myself yet, but according to documentation this should work.
Regards,
Alex
From: qt-interest-bounces at trolltech.com [mailto:qt-interest-bounces at trolltech.com] On Behalf Of Miguel Cardenas
Sent: Friday, August 14, 2009 10:41 AM
To: qt-interest at trolltech.com
Subject: [Qt-interest] QProgresBar + QThread = It is not safe to use pixmaps outside the GUI thread
Hello
I'm developing a QMainWindow application, it launches a QThread (non graphic, just internal tasks) to perform some operation in the background to avoid blocking the user interface while it works...
In the QMainWindow object there is a QProgressBar to show the progress of the process (in background), so I pass the progress bar pointer to the QThread object before running, so it can show the progress, but it appears not to work, I get these errors in console and no progress is shown:
QPixmap: It is not safe to use pixmaps outside the GUI thread
.
. // about 50 of these
.
QPixmap: It is not safe to use pixmaps outside the GUI thread
QPainter::begin: Cannot paint on a null pixmap
QPainter::setPen: Painter not active
X Error: BadDrawable (invalid Pixmap or Window parameter) 9
Major opcode: 62 (X_CopyArea)
Resource id: 0x0
.
. // abouth 50 of these others
.
X Error: BadDrawable (invalid Pixmap or Window parameter) 9
Major opcode: 62 (X_CopyArea)
Resource id: 0x0
My doubt is, how can I do to access the QMainWindow::QProgressBar from the QThread? I was thinking of creating the bar inside the QThread, then get the QProgressBar pointer from it and then insert it into the QMainWindow layout... but it should be a mess...
Any idea of how can I solve the problem?
I am using Linux Slackware 12.1 with KDE
Thanks
--
Miguel Cardenas
---------------------------------------------------------------------------------------------------
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."
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.qt-project.org/pipermail/qt-interest-old/attachments/20090814/615e7eba/attachment.html
More information about the Qt-interest-old
mailing list