Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. How to stop a thread without signal & slot?
Forum Updated to NodeBB v4.3 + New Features

How to stop a thread without signal & slot?

Scheduled Pinned Locked Moved Unsolved General and Desktop
2 Posts 2 Posters 162 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    makopo
    wrote on last edited by makopo
    #1

    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. in DeckLinkToCv), 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

    jsulmJ 1 Reply Last reply
    0
    • M makopo

      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. in DeckLinkToCv), 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

      jsulmJ Offline
      jsulmJ Offline
      jsulm
      Lifetime Qt Champion
      wrote on last edited by
      #2

      @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

      https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      3

      • Login

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • Users
      • Groups
      • Search
      • Get Qt Extensions
      • Unsolved