How to stop a thread without signal & slot?
-
Hi,
as descriped here, I implement a function (DeckLinkToCv) thats runs in an other thread than the main thread. This function is a slot and starts running when I press a start button. When I press the stop button the main function stops but the "threaded-function" did not stop running (in fact the program stops running when the signal is null).
I tried to stop the thread with signal und slot, and emit a signal at different positions (f.e. inDeckLinkToCv
), but this did not work.QObject::connect(m_videoScreenHelper, &VideoScreenHelper::SendFrame, m_convertVideo, &ConvertVideoFormat::DeckLinkToCv, Qt::QueuedConnection); QObject::connect(m_convertVideo, &ConvertVideoFormat::finished, &m_thread, &QThread::quit); QObject::connect(m_convertVideo, &ConvertVideoFormat::finished, m_convertVideo, &ConvertVideoFormat::deleteLater); QObject::connect(&m_thread, &QThread::finished, &m_thread, &QThread::deleteLater);
I try to emit
finished()
into the stop button function but this produces some crazy linking errors. Is there a way to stop a thread without signal and slot?Kind regards
-
@makopo quit() should work if your thread has an event loop.
If not, take a look at https://doc.qt.io/qt-5/qthread.html#isInterruptionRequested and https://doc.qt.io/qt-5/qthread.html#requestInterruption