[Qt-interest] Warning: QObject::startTimer: timers cannot be started from another thread

Eirik Ulvik eiriku at simsurgery.com
Mon Mar 22 09:29:03 CET 2010



Den 18.03.2010 21:03, skrev Sean Harmer:
> Hi,
> 
> Eirik Ulvik wrote:
>> I am in the process of making our application multithreaded. The problem
>> I am now facing is the error message in the subject is printed all the
>> time while executing the program. I also get the same sort of message
>> for QObject::killTimer. After googling a bit I found, as expected, that
>> this is related to doing GUI operation in threads other than the main Qt
>> GUI thread.
>>
>> My next step is to strip all GUI operations from the code that runs in a
>> separate thread. As much of this code is quite old and did not separate
>> GUI code from other code, locating the code in question is difficult. So
>> my question to the list is if anyone has had experience in a similar
>> situation or have some general pointers on good ways of pin pointing GUI
>> code I would be very grateful.
> 
> Do either:
> 
> (1) Set break points on all occurrances of startTimer()
> (2) Set break point in QObject::startTimer() and look at the stack to 
> see where it is being called in your code.
> (3) export the Q_FATAL_WARNINGS environment variable and run your app in 
> a debugger. It will abort whenever Qt issues a warning. Again look at 
> the stack to see where in your code it is being triggered.
> 
> Once you find where it is being called, find from which thread's context 
> it is being called and fix it ;-) Once you find the problem spots and 
> can make a small compileable example for each type of problem post it to 
> the list and we can tell you how to resolve them.
> 
> A good approach when using QObjects in worker threads is to not make 
> your QThread subclass do the work. This is because the thread object 
> itself has affinity with the thread that created it - usually the main 
> GUI thread. Instead, create a QObject derived object in the QThread's 
> run() function and have that do the work instead. That way, your QObject 
> will have affinity with the worker thread and not the main thread.
> 
> Good luck,
> 
> Sean
> _______________________________________________
> Qt-interest mailing list
> Qt-interest at trolltech.com
> http://lists.trolltech.com/mailman/listinfo/qt-interest

Thanks a lot for your reply. I will give this a try. Btw. I think the Qt
macro should be QT_FATAL_WARNINGS.

Regards,
Eirik

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 551 bytes
Desc: OpenPGP digital signature
Url : http://lists.qt-project.org/pipermail/qt-interest-old/attachments/20100322/652effaa/attachment.bin 


More information about the Qt-interest-old mailing list