Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Update: Forum Guidelines & Code of Conduct


    Qt World Summit: Early-Bird Tickets

    Stop all threads

    General and Desktop
    4
    6
    4312
    Loading More Posts
    • 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
      lucky last edited by

      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 Reply Quote 0
      • D
        dialingo last edited by

        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 Reply Quote 0
        • L
          lucky last edited by

          Thank you.

          1 Reply Last reply Reply Quote 0
          • A
            andre last edited by

            You might consider using a maximum wait time.

            1 Reply Last reply Reply Quote 0
            • F
              florent.revelut last edited by

              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 Reply Quote 0
              • D
                dialingo last edited by

                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 Reply Quote 0
                • First post
                  Last post