PDA

View Full Version : Can a timer from another class be called from a thread?



pooch
21st January 2014, 06:05
I have created a class which contains a timer. The timer works fine normally when i start or stop it from the same class. but i need to use the same timer from a thread to check the data arrival in i/o of my laptop. this gives me the following error...
QObject::killTimer: timers cannot be stopped from another thread
QObject::startTimer: timers cannot be started from another thread

What is the actual problem and what should i do?
I cannot post my codes here.

anda_skoa
21st January 2014, 08:32
I have created a class which contains a timer. The timer works fine normally when i start or stop it from the same class. but i need to use the same timer from a thread to check the data arrival in i/o of my laptop.

What is the timer's purpose?


QObject::killTimer: timers cannot be stopped from another thread
QObject::startTimer: timers cannot be started from another thread


start() and stop() are slots so the can be called through a cross-thread signal/slot connection.


I cannot post my codes here.

In such cases it is almost always possible to create a simple project that shows the same behavior.

Cheers,
_

pooch
22nd January 2014, 09:25
the purpose of timer is to timeout when no signal arrives in my serial port. this timer is started within the class it is created in. but when i access the class from the thread, it shows the timer error i mentioned above. I don't access the timer directly from the thread, a function in that class does.

anda_skoa
22nd January 2014, 12:28
the purpose of timer is to timeout when no signal arrives in my serial port.

And the data is read by the thread?
Wouldn't it be better to run the timer in the same thread and either signal data arrival or timeout?
I.e. encapsulate all in your data handler class?

Alternatively you can run the timer in the receiver thread (probably your main thread) and just reset it in the slot that handles the data signal from your I/O thread.




I don't access the timer directly from the thread, a function in that class does.
The methods are clearly executed by the other thread, hence the error.

Cheers,
_