Using QTimer in a Pushbutton QT C++.
-
Hi,
I am working on a QWidget application. I want to use QTimer. I have created a timer and attached its TimeOut Signal to a slot in the constructor. Now I want to start the timer when the user clicks on Start pushbutton and stop the timer when the user clicks on stop pushbutton. But when I call the timer->start function in the pushbutton (in which I am calling a different function). qt throws an message "Timer cannot be started from another thread.", "Timer cannot be stopped in another thread."
Is there any way to implement the above said functionality.
Any help would be appreciated.
-
Hi,
I am working on a QWidget application. I want to use QTimer. I have created a timer and attached its TimeOut Signal to a slot in the constructor. Now I want to start the timer when the user clicks on Start pushbutton and stop the timer when the user clicks on stop pushbutton. But when I call the timer->start function in the pushbutton (in which I am calling a different function). qt throws an message "Timer cannot be started from another thread.", "Timer cannot be stopped in another thread."
Is there any way to implement the above said functionality.
Any help would be appreciated.
@mbatra said in Using QTimer in a Pushbutton QT C++.:
qt throws an message "Timer cannot be started from another thread.", "Timer cannot be stopped in another thread."
As the message, but not your explanation, tells us, you are using multiple threads. And you cannot start/stop a
QTimerfrom a thread different from where it was created/currently lives. -
@mbatra said in Using QTimer in a Pushbutton QT C++.:
qt throws an message "Timer cannot be started from another thread.", "Timer cannot be stopped in another thread."
As the message, but not your explanation, tells us, you are using multiple threads. And you cannot start/stop a
QTimerfrom a thread different from where it was created/currently lives.@JonB
You can implement a slot (or two) in an object living the the timer‘s thread, that starts/stops the timer. That slot can be invoked directly or by means of a signal connection. -
@JonB
You can implement a slot (or two) in an object living the the timer‘s thread, that starts/stops the timer. That slot can be invoked directly or by means of a signal connection. -
@Axel-Spoerl
Hi Axel. Not sure why you are addressing me here? Is there something I have not understood, or did you intend it as a suggestion to @mbatra, the OP?@JonB
Hi Jon,
It was wrong to address you. I meant the OP….
Sorry for the confusion!
Cheers
Axel