[Interest] Event handling for QObjects created before QApplication

Thiago Macieira thiago.macieira at intel.com
Sun Oct 5 22:22:57 CEST 2014


On Sunday 05 October 2014 08:50:11 Alan Ezust wrote:
> Here are my suggested changes to the threads.qdoc. What do you think?
> 
> diff --git a/doc/src/frameworks-technologies/threads.qdoc
> b/doc/src/frameworks-technologies/threads.qdoc
> index 5e92425..b5136fe 100644
> --- a/doc/src/frameworks-technologies/threads.qdoc
> +++ b/doc/src/frameworks-technologies/threads.qdoc
> @@ -632,13 +632,23 @@
>      event loop. The thread in which a QObject lives is available using
>      QObject::thread().
> 
> -    Note that for QObjects that are created before QApplication,
> -    QObject::thread() returns zero. This means that the main thread
> -    will only handle posted events for these objects; other event
> -    processing is not done at all for objects with no thread. Use the
> -    QObject::moveToThread() function to change the thread affinity for
> -    an object and its children (the object cannot be moved if it has a
> -    parent).
> +    Note that for QObjects that are created before the QApplication,
> +    QObject::thread() returns zero. This means that the main thread will
> +    not handle events for these objects. Event processing is not done at
> +    all for objects with no thread.
> +
> +    The above paragraph is for academic interest only. In general,
> +    creating QObjects before the QApplication is not supported
> +    and can lead to weird crashes on exit, depending on the platform.
> +    This means static instances of QObject are also not supported. A
> +    properly structured single or multi-threaded application should make
> +    the QApplication be the last QObject to be destroyed before exiting.
> +
> +    The QObject::moveToThread() function can be used to change the
> +    thread affinity for a QObject and its children (the object cannot be
> +    moved if it has a parent). Unfortunately, QObject::moveToThread()
> +    does not work properly for complex QObjects with sub-QObjects, so it
> +    is better to create these in the actual thread that uses them.

Looks good, except for the last sentence (starting at "Unfortunately"). Please 
remove that sentence and submit to codereview.

-- 
Thiago Macieira - thiago.macieira (AT) intel.com
  Software Architect - Intel Open Source Technology Center




More information about the Interest mailing list