[Interest] moveToThread used in constructor to move "this"

André Somers andre at familiesomers.nl
Thu Feb 25 13:46:25 CET 2016



Op 25/02/2016 om 11:32 schreef Prav:
>> Would it be possible to circumvent this issue by moving the thread
>> object onto its own thread too?
>>      Foo() : QObject(nullptr) {
>>         moveToThread(&m_thread);
>>         m_thread->moveToThread(m_thread);
>>         m_thread.start();
>>      }
>> Looks like the much debated move-QThread-onto-its-own-thread
>> antipattern, but it's not the same obviously.
> Do you see any help of that action?
Not sure what you are asking here.
> And  how  destructor will look like?
Same as it was before was the idea:

~Foo() {
       m_thread.quit();
       m_thread.wait();
    }

> If it will be as it was before ... this mean
> that  m_thread  thread  will  call  its  quit() function and
> I did not get
> who  after  that  would  release memory allocated to Foo?
Good point. So I guess Foo itself would not be properly destructed this 
way. Which is what Thiago was saying the first place, reading it back.

So, indeed, the conclusion is: this won't work properly.
>
> PS
> you probably ment to write "." instead of "->":
>    m_thread.moveToThread(m_thread);
> is not it?
Yeah. Not used to using QObjects as members; I usually use 
pointers-to-QObjects.

André




More information about the Interest mailing list