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 wait for a thread to complete?
Forum Updated to NodeBB v4.3 + New Features

How to wait for a thread to complete?

Scheduled Pinned Locked Moved General and Desktop
4 Posts 4 Posters 4.3k Views 1 Watching
  • 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.
  • C Offline
    C Offline
    chcw
    wrote on last edited by
    #1

    In my main GUI thread, I start a new thread and need to wait until the thread is terminated normally. When waiting the thread, I do not want the main GUI thread loses the reponses, just like WaitForMultipleObjects in Windows SDK API. Is there a similar function that can implement this?

    Thanks

    1 Reply Last reply
    0
    • JKSHJ Offline
      JKSHJ Offline
      JKSH
      Moderators
      wrote on last edited by
      #2

      Hi,

      It depends on how you started the thread. What class did you use?

      For QThread, listen for the QThread::finished() signal. The signal is emitted when the thread stops. Documentation at https://qt-project.org/doc/qt-5/qthread.html

      Qt Doc Search for browsers: forum.qt.io/topic/35616/web-browser-extension-for-improved-doc-searches

      1 Reply Last reply
      0
      • Q Offline
        Q Offline
        qxoz
        wrote on last edited by
        #3

        You can use something like that:
        @QEventLoop loop;
        connect(thread, &QThread::finished, &loop, &QEventLoop::quit);
        thread->start();
        loop.exec();@

        1 Reply Last reply
        0
        • IamSumitI Offline
          IamSumitI Offline
          IamSumit
          wrote on last edited by
          #4

          Hii.

          and if you want to stop/finished your thread before quitting from event loop you can use
          connect(thread,SIGNAL(finished()),thread,SLOT(deleteLater())); as well

          Be Cute

          1 Reply Last reply
          0

          • Login

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