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. Stoped thread still receives signals
Forum Updated to NodeBB v4.3 + New Features

Stoped thread still receives signals

Scheduled Pinned Locked Moved General and Desktop
5 Posts 3 Posters 1.5k 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.
  • L Offline
    L Offline
    lor.lucignano
    wrote on last edited by
    #1

    Hi everybody,
    I 've a 2 classes that extend Qthread, connected by signlas/slots. The first one sends signals to the latter. The second class lives for 10 cycles, then the run() returns. However, even if the isRunning() is false, the class still reacts to the signals!
    Where am i wrong?
    Thank you :)

    1 Reply Last reply
    0
    • K Offline
      K Offline
      KA51O
      wrote on last edited by
      #2

      It doesn't matter if the run() function has returned, your QThread subclass still is alive and living in the main thread (thus having a working eventloop).
      On a side note, consider NOT to subclass from QThread and instead to use the worker object approach which is considered best practise for QThread. For more information follow these links:
      "You're doing it wrong":http://blog.qt.digia.com/blog/2010/06/17/youre-doing-it-wrong/
      "best practise for QThread":http://qt-project.org/wiki/QThreads_general_usage
      "doc note in QThread reference":http://qt-project.org/doc/qt-4.8/QThread.html#notes

      1 Reply Last reply
      0
      • L Offline
        L Offline
        lor.lucignano
        wrote on last edited by
        #3

        Ok thank you. So i need to notify this to main thread to stop the interaction....

        1 Reply Last reply
        0
        • C Offline
          C Offline
          Code_ReaQtor
          wrote on last edited by
          #4

          After using QObject::connect() for your signal and slot..... it is better to use QObject::disconnect()

          I think it is a safer and cleaner way. I use it most of the time. :)

          Please visit my open-source projects at https://github.com/Code-ReaQtor.

          1 Reply Last reply
          0
          • K Offline
            K Offline
            KA51O
            wrote on last edited by
            #5

            [quote author="lor.lucignano" date="1354629242"]Ok thank you. So i need to notify this to main thread to stop the interaction....
            [/quote]
            Just emit a signal right before the run function terminates. Catch the signal somewhere where you have access to the QThread object and disconnect it.

            But seriously you should not subclass QThread unless you absolutely have to.

            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