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. Is QThread::exit() thread-safe?
Qt 6.11 is out! See what's new in the release blog

Is QThread::exit() thread-safe?

Scheduled Pinned Locked Moved General and Desktop
4 Posts 3 Posters 4.1k 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.
  • T Offline
    T Offline
    thesourcehim
    wrote on last edited by
    #1

    I understand that QThread::exec() must of course be called from QThread::run(). But is it safe to call exit() from another thread to stop event loop and therefore end default run() execution or exit() should also be called inside that thread only?

    1 Reply Last reply
    0
    • F Offline
      F Offline
      franku
      wrote on last edited by
      #2

      This is the common way I stop my threads running.

      This, Jen, is the internet.

      1 Reply Last reply
      0
      • W Offline
        W Offline
        webmaster.skelton
        wrote on last edited by
        #3

        It would be safer to use signals and slots to handle this and have the thread itself call exit. You will retain the same functionality but will not have to be concerned on the thread context itself (i.e did you call exit from within a form, etc).

        1 Reply Last reply
        0
        • F Offline
          F Offline
          franku
          wrote on last edited by
          #4

          One additional idea. In that case the signal slot connection has to be set up with Qt::QueuedConnection so the slot is not being executed in the context of the signalling thread if there was any.

          This, Jen, is the internet.

          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