Answer the question
In order to leave comments, you need to log in
How to stop a timer from another thread?
Greetings!
I continue to deal with threads ...
In general, there is a class MyClass
MyClass::MyClass(QObject * parent =0) {
_thread = new QThread(0); //-- поток не должен иметь родителя, что бы он не снёс его ненароком, пока выполняется
connect(_thread, &QThread::started, this, &MyClass::process); //-- при запуске потока сразу начинаем работу
moveToThread(_thread);
}
void MyClass::process()
{
myTimer = new QTimer(this);
....
}
void MyClass::stopTimer() {
myTimer->stop();
}
QObject::killTimer: Timers cannot be stopped from another thread
Answer the question
In order to leave comments, you need to log in
Communication between threads should be only through the signal slot. It is therefore impossible to stop the timer without a signal.
The timer should also be deleted in the thread in which it was created.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question