[Qt-interest] timers cannot be started from another thread
Matthias Pospiech
matthias.pospiech at gmx.de
Tue Jul 21 09:50:42 CEST 2009
Thiago Macieira schrieb:
>
>> If I change the timer to a pointer and construct it in the run() method,
>> then I get the error:
>>
>> QObject: Cannot create children for a parent that is in a different thread.
>> (Parent is GratingVariationShowMovie(0x1efe100), parent's thread is
>> QThread(0xe1
>> 7080), current thread is GratingVariationShowMovie(0x1efe100)
>>
>
> That happens because you passed "this" as parent. And, like I explained above,
> objects belong to the thread they were created in. This applies even to
> classes derived from QThread: those objects belong to the main thread.
>
> You should either move the QThread to its own thread (i.e. moveToThread(this))
> or you should not use a parent for your QTimer.
>
>
Ok, I moved it as a pointer to the run function without a parent in the
constructor. But now the application crashes as soon as the signal is
triggered:
ASSERT failure in QPersistentModelIndex::~QPersistentModelIndex:
"persistent mod
el indexes corrupted", file kernel\qabstractitemmodel.cpp, line 475
this I can not debug, nor do I understant it...
Matthias
More information about the Qt-interest-old
mailing list