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. Stop all threads

Stop all threads

Scheduled Pinned Locked Moved General and Desktop
6 Posts 4 Posters 4.6k 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.
  • L Offline
    L Offline
    lucky
    wrote on last edited by
    #1

    I need to complete the work threads before closing the application. I have done so:
    @
    connect(quitAction, SIGNAL(triggered()), this, SLOT(quit()));

    ...........

    void MainWindow::quit()
    {
    thread_update_base.exit();
    thread_update_base.wait();
    qApp->quit();
    }
    @

    So it will be correct in terms of security? If not, please show how to correctly stop all threads.

    1 Reply Last reply
    0
    • D Offline
      D Offline
      dialingo
      wrote on last edited by
      #2

      It depends on what is going on in thread_update_base.
      Your code does not look bad actually. You stop the event loop and then you politely wait.
      However you need to ask yourself if your thread needs additional cleanup and if it is ok to stop the thread on termination of any method which happens to run when you call exit().
      If you do not have an objection go ahead. Otherwise it is better to send a signal to the worker thread, pick the signal up, do the cleanup and then you exit().

      1 Reply Last reply
      0
      • L Offline
        L Offline
        lucky
        wrote on last edited by
        #3

        Thank you.

        1 Reply Last reply
        0
        • A Offline
          A Offline
          andre
          wrote on last edited by
          #4

          You might consider using a maximum wait time.

          1 Reply Last reply
          0
          • F Offline
            F Offline
            florent.revelut
            wrote on last edited by
            #5

            If you have more than one thread to terminate, keep in mind that terminating one thread might trigger som event to be handled by another one...
            To keep it simple, I would advise to keep a drawing of interaction, to know in which order terminate and when to wait. Definitely, not as easy as it sounds :-)

            1 Reply Last reply
            0
            • D Offline
              D Offline
              dialingo
              wrote on last edited by
              #6

              When the timer times out the Terminator enters the scene. Hasta la vista baby. The application may be severly hit. Continueing from here is dangerous and can lead to the land of pain.
              Was that too dramatic?

              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