[Qt-interest] Delete QObjects which are moved to different thread
Giuseppe D'Angelo
dangelog at gmail.com
Wed Oct 26 09:37:42 CEST 2011
On 26 October 2011 09:34, Giuseppe D'Angelo <dangelog at gmail.com> wrote:
> On 26 October 2011 09:27, Wilhelm <wilhelm.meier at fh-kl.de> wrote:
>> Hi,
>>
>> if I move a QObject to a different QThread and then destroy this object
>> deferred, the dtor is called by this thread, if it is running: ok.
>>
>> But if the other thread is not running, I can't use deferred deletion
>> since there is no running event loop.
>> Trying to delete the object from the main thread via delete operator,
>> the dtor ist called from a different thread than the main thread: I
>> assume the QObject-dtor detects that the object belongs to a different
>> thread and if that is not running it starts a new thread to execute the
>> dtor. Right?
>
> Wrong.
Sorry -- I hit the "send" button instead of the "save" button. :)
Still, it's wrong. The object gets deleted from the main thread, and
that's something you shouldn't do (QObjects are reentrant and not
thread safe -- they're supposed to be accessed only from the thread
they're living in).
Why did you move the object in the first place if you don't have a
running thread with a running event loop? Or, if that thread has
finished, why didn't you clean up the objects living in it?
Cheers,
--
Giuseppe D'Angelo
More information about the Qt-interest-old
mailing list