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. Qt::BlockingQueuedConnection With Null Receiver?
QtWS25 Last Chance

Qt::BlockingQueuedConnection With Null Receiver?

Scheduled Pinned Locked Moved Unsolved General and Desktop
multithread
8 Posts 4 Posters 1.9k 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.
  • W Offline
    W Offline
    wumpus7
    wrote on last edited by
    #1

    Howdy,

    My comms thread sometimes needs to communicate with my main thread; in particular I have a backend 'device' class (comms) that is represented to the user by a 'UIdevice' class (main). At teardown, I need to delete both classes, and, as of now, this can happen in a variety of ways.

    Anyway, what should I expect to happen if the comms device emits a Qt::BlockingQueuedConnection signal to a UIdevice that no longer exists? I'm suspecting deadlock. If so, is there a way to check for the existence of the receiver before emitting the signal?

    Thanks,
    Alex

    JKSHJ J.HilkJ 2 Replies Last reply
    0
    • W wumpus7

      Howdy,

      My comms thread sometimes needs to communicate with my main thread; in particular I have a backend 'device' class (comms) that is represented to the user by a 'UIdevice' class (main). At teardown, I need to delete both classes, and, as of now, this can happen in a variety of ways.

      Anyway, what should I expect to happen if the comms device emits a Qt::BlockingQueuedConnection signal to a UIdevice that no longer exists? I'm suspecting deadlock. If so, is there a way to check for the existence of the receiver before emitting the signal?

      Thanks,
      Alex

      JKSHJ Offline
      JKSHJ Offline
      JKSH
      Moderators
      wrote on last edited by
      #2

      @wumpus7 said in Qt::BlockingQueuedConnection With Null Receiver?:

      what should I expect to happen if the comms device emits a Qt::BlockingQueuedConnection signal to a UIdevice that no longer exists?

      When a QObject's destructor is called, it automatically disconnects from all existing signals so you shouldn't have to worry.

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

      1 Reply Last reply
      4
      • W wumpus7

        Howdy,

        My comms thread sometimes needs to communicate with my main thread; in particular I have a backend 'device' class (comms) that is represented to the user by a 'UIdevice' class (main). At teardown, I need to delete both classes, and, as of now, this can happen in a variety of ways.

        Anyway, what should I expect to happen if the comms device emits a Qt::BlockingQueuedConnection signal to a UIdevice that no longer exists? I'm suspecting deadlock. If so, is there a way to check for the existence of the receiver before emitting the signal?

        Thanks,
        Alex

        J.HilkJ Offline
        J.HilkJ Offline
        J.Hilk
        Moderators
        wrote on last edited by J.Hilk
        #3

        @wumpus7
        I wanted to expand an @JKSH answer.
        If you did all your connects in a proper way. You do not need to to worry. If either sender or receiver object is destroyed. The connect is dissolved.

        But, if you didn‘t specify a receiver, which you can get away with, if you connect to a lambda. Or if you simply omit it, in which case it defaults to this As receiver object.
        Than you may run into trouble, where you connect to a function/class or even object that no longer exists.

        Make sure all your lambda connects have reference receiver objects, and you should be always fine 😉


        Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


        Q: What's that?
        A: It's blue light.
        Q: What does it do?
        A: It turns blue.

        W kshegunovK 2 Replies Last reply
        4
        • J.HilkJ J.Hilk

          @wumpus7
          I wanted to expand an @JKSH answer.
          If you did all your connects in a proper way. You do not need to to worry. If either sender or receiver object is destroyed. The connect is dissolved.

          But, if you didn‘t specify a receiver, which you can get away with, if you connect to a lambda. Or if you simply omit it, in which case it defaults to this As receiver object.
          Than you may run into trouble, where you connect to a function/class or even object that no longer exists.

          Make sure all your lambda connects have reference receiver objects, and you should be always fine 😉

          W Offline
          W Offline
          wumpus7
          wrote on last edited by wumpus7
          #4

          Thanks for the quick replies!

          I'd somehow missed the fact that the connect() should be broken by destruction - that totally makes sense.

          Just to be clear, though, the sequence of events for emitting a blocking signal isn't:

          1. Block
          2. Send signal (or don't in the case of no connection)
          3. Await return

          Is it? Because the fact that the connection was gone wouldn't necessarily help if that were true, as the block would still occur, and the return still wouldn't.

          I'm hoping that the sequence is, instead:

          1. Send signal (or don't in case of no connection)
          2. Block and await return (if signal sent in step 1)

          (And no, I'm not doing anything fancy with lambdas or defaults, so that shouldn't matter in my case.)

          JKSHJ 1 Reply Last reply
          0
          • J.HilkJ J.Hilk

            @wumpus7
            I wanted to expand an @JKSH answer.
            If you did all your connects in a proper way. You do not need to to worry. If either sender or receiver object is destroyed. The connect is dissolved.

            But, if you didn‘t specify a receiver, which you can get away with, if you connect to a lambda. Or if you simply omit it, in which case it defaults to this As receiver object.
            Than you may run into trouble, where you connect to a function/class or even object that no longer exists.

            Make sure all your lambda connects have reference receiver objects, and you should be always fine 😉

            kshegunovK Offline
            kshegunovK Offline
            kshegunov
            Moderators
            wrote on last edited by kshegunov
            #5

            @J.Hilk said in Qt::BlockingQueuedConnection With Null Receiver?:

            Or if you simply omit it, in which case it defaults to this As receiver object

            This is incorrect. The receiver's thread in that case is the emitter's thread.

            Make sure all your lambda connects have reference receiver objects

            Good advice! Just to reiterate, don't connect lambdas without specifying a context object!

            Read and abide by the Qt Code of Conduct

            J.HilkJ 1 Reply Last reply
            1
            • kshegunovK kshegunov

              @J.Hilk said in Qt::BlockingQueuedConnection With Null Receiver?:

              Or if you simply omit it, in which case it defaults to this As receiver object

              This is incorrect. The receiver's thread in that case is the emitter's thread.

              Make sure all your lambda connects have reference receiver objects

              Good advice! Just to reiterate, don't connect lambdas without specifying a context object!

              J.HilkJ Offline
              J.HilkJ Offline
              J.Hilk
              Moderators
              wrote on last edited by
              #6

              @kshegunov said in Qt::BlockingQueuedConnection With Null Receiver?:

              @J.Hilk said in Qt::BlockingQueuedConnection With Null Receiver?:

              Or if you simply omit it, in which case it defaults to this As receiver object

              This is incorrect. The receiver's thread in that case is the emitter's thread.

              Maybe I expressed myself not good enough, what I meant was this overload:

              http://doc.qt.io/qt-5/qobject.html#connect-2

              0_1543470535444_abbe5f74-2f92-41cb-86b9-1a8f7a0e64e0-image.png

              not the relation between calling and executing threads :-)


              Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


              Q: What's that?
              A: It's blue light.
              Q: What does it do?
              A: It turns blue.

              kshegunovK 1 Reply Last reply
              0
              • J.HilkJ J.Hilk

                @kshegunov said in Qt::BlockingQueuedConnection With Null Receiver?:

                @J.Hilk said in Qt::BlockingQueuedConnection With Null Receiver?:

                Or if you simply omit it, in which case it defaults to this As receiver object

                This is incorrect. The receiver's thread in that case is the emitter's thread.

                Maybe I expressed myself not good enough, what I meant was this overload:

                http://doc.qt.io/qt-5/qobject.html#connect-2

                0_1543470535444_abbe5f74-2f92-41cb-86b9-1a8f7a0e64e0-image.png

                not the relation between calling and executing threads :-)

                kshegunovK Offline
                kshegunovK Offline
                kshegunov
                Moderators
                wrote on last edited by
                #7

                @J.Hilk said in Qt::BlockingQueuedConnection With Null Receiver?:

                Maybe I expressed myself not good enough, what I meant was this overload

                Yes, apparently we are talking about different things.

                Read and abide by the Qt Code of Conduct

                1 Reply Last reply
                0
                • W wumpus7

                  Thanks for the quick replies!

                  I'd somehow missed the fact that the connect() should be broken by destruction - that totally makes sense.

                  Just to be clear, though, the sequence of events for emitting a blocking signal isn't:

                  1. Block
                  2. Send signal (or don't in the case of no connection)
                  3. Await return

                  Is it? Because the fact that the connection was gone wouldn't necessarily help if that were true, as the block would still occur, and the return still wouldn't.

                  I'm hoping that the sequence is, instead:

                  1. Send signal (or don't in case of no connection)
                  2. Block and await return (if signal sent in step 1)

                  (And no, I'm not doing anything fancy with lambdas or defaults, so that shouldn't matter in my case.)

                  JKSHJ Offline
                  JKSHJ Offline
                  JKSH
                  Moderators
                  wrote on last edited by
                  #8

                  @wumpus7 said in Qt::BlockingQueuedConnection With Null Receiver?:

                  Just to be clear, though, the sequence of events for emitting a blocking signal isn't:

                  1. Block
                  2. Send signal (or don't in the case of no connection)
                  3. Await return

                  Is it? Because the fact that the connection was gone wouldn't necessarily help if that were true, as the block would still occur, and the return still wouldn't.

                  I'm hoping that the sequence is, instead:

                  1. Send signal (or don't in case of no connection)
                  2. Block and await return (if signal sent in step 1)

                  Try it and find out :) 'Tis the hacker way.

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

                  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