[Qt-interest] QObject::moveToThread: Widgets cannot be moved to a new thread
Arnold Krille
arnold at arnoldarts.de
Fri Jul 31 10:02:22 CEST 2009
On Friday 31 July 2009 09:40:46 alexandre.raczynski at technog wrote:
> I know that I am playing with fire
You are not playing with fire, you are playing with a firefront!
> that's why I asked if someone knows
> the real technical limitation(s) behind the fact that it is not
> recommended to instanciate a widget outside the main-thread (by the way
> Qt does not trigger a warning for that).
The technical reason is (as explained at various places in the docs and
explained regularly here on the list) that all the gui-interacting things have
to be done in the main thread (where main-thread is not necessarily the one
where main() is executed but the one where QApplication is instantiated).
Because at least some of the Qt-supported graphics systems need all the
communication to be done by one thread (X11 for example).
And creating a QWidget in another thread and moving it to the gui-thread
before it is shown might work now but might not work in any future (or past!)
release of Qt because there could very well be some stuff inside the
constructor (or somewhere else) that requires a connection to the underlying
graphics. It might not even work on other architectures...
Simple and clear: Don't use any QWidget-derived classes outside the thread
that instantiated QApplication.
Have fun,
Arnold
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 197 bytes
Desc: This is a digitally signed message part.
Url : http://lists.qt-project.org/pipermail/qt-interest-old/attachments/20090731/d57b9745/attachment.bin
More information about the Qt-interest-old
mailing list