[Interest] question about moveToThread docs

André Somers andre at familiesomers.nl
Wed Feb 11 08:32:26 CET 2015


Alan Ezust schreef op 10-2-2015 om 23:48:
> from the documentation of QObject::moveToThread():
>
>     \note A QObject's member variables \e{do not} automatically become
>     its children. The parent-child relationship must be set by either
>     passing a pointer to the child's \l{QObject()}{constructor}, or by
>     calling setParent(). Without this step, the object's member variables
>     will remain in the old thread when moveToThread() is called.
>
> Is this talking about member variables of type QObject ?
> As in, "subobjects" ?
Yes.
>
> subobjects of type QObject that also have a parent set, might get 
> destructed twice, but is that what this above paragraph is recommending?
>
Not really. It just warns about the (lack of) effects of moveToThread on 
member objects that do not partake in a parent-child relationship. How 
you solve that is up to you.

You could simply elect to not use such members in contexts where such 
thread-moves happen. Or you could elect to remove the parent-child 
relationship in your destructor. Or you could make sure that if 
moveToThread is called on your worker, it is also called on its 
non-child member objects by listening for the appropriate event and then 
also moving any child object to the same thread. And perhaps there are 
even more options how you can handle this.

André




More information about the Interest mailing list