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. Signal handling with uninitialized receiver

Signal handling with uninitialized receiver

Scheduled Pinned Locked Moved Solved General and Desktop
6 Posts 4 Posters 606 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.
  • R Offline
    R Offline
    Redman
    wrote on last edited by Redman
    #1

    Hello Qt Forum,

    currently I'm trying to understand a piece of software that I have at hands. Its a library, so debugging is complicated.

    The library is used by initializing ClassFoo().

    ClassFoo then emits a signal which is caught by ClassReceiver() without ever initializing the receiver. ClassReceiver is not a member. The signal is simply emitted.

    How does that work? Is the ctor of ClassReceiver invoked the instance the signal is sent? Does it have to do anything with the facts its a library?

    Kind regards

    jsulmJ JonBJ 2 Replies Last reply
    0
    • R Redman

      Hello Qt Forum,

      currently I'm trying to understand a piece of software that I have at hands. Its a library, so debugging is complicated.

      The library is used by initializing ClassFoo().

      ClassFoo then emits a signal which is caught by ClassReceiver() without ever initializing the receiver. ClassReceiver is not a member. The signal is simply emitted.

      How does that work? Is the ctor of ClassReceiver invoked the instance the signal is sent? Does it have to do anything with the facts its a library?

      Kind regards

      jsulmJ Offline
      jsulmJ Offline
      jsulm
      Lifetime Qt Champion
      wrote on last edited by
      #2

      @Redman said in Signal handling with uninitialized receiver:

      ClassFoo then emits a signal

      Do you mean Qt signal?
      Qt signals can only be received by instances of classes. So, there must be ClassReceiver instance somewhere and there must be a connect(...) call somewhere to connect the sender and receiver. Search for this in the code.
      Signals can be emitted without any receivers connected, that doesn't matter.

      https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      1
      • R Redman

        Hello Qt Forum,

        currently I'm trying to understand a piece of software that I have at hands. Its a library, so debugging is complicated.

        The library is used by initializing ClassFoo().

        ClassFoo then emits a signal which is caught by ClassReceiver() without ever initializing the receiver. ClassReceiver is not a member. The signal is simply emitted.

        How does that work? Is the ctor of ClassReceiver invoked the instance the signal is sent? Does it have to do anything with the facts its a library?

        Kind regards

        JonBJ Online
        JonBJ Online
        JonB
        wrote on last edited by JonB
        #3

        @Redman
        Not sure what you are asking/claiming?

        ClassFoo instances emit signals regardless of whether any slots have or have not been connected.

        ClassReceiver must have an instance created and connect()ed to an emitter instance for anything to happen. You gave to create receiver (and sender) instances explicitly, and connect them, Qt does not do this automatically. (Your code could have been written so that slots are connected to signals semi-automatically depending on name, but let's not go there unless we find it's in your code.)

        1 Reply Last reply
        0
        • R Offline
          R Offline
          Redman
          wrote on last edited by
          #4

          Yes, a QT Signal is emitted.

          I can not find any initializations of the Receiver class. Wether in the library nor in the application that uses the library.

          The Receiver class calls connect(...) on the signals in question and the connect(...) is called in the ctor.

          I generated some output to try to understand if the signals are processed. Actually they are.

          ClassFoo sends QtSignal, Receiver receives and calls the slot which is located in ClassSlot.

          So the signal handling seems to work fine. And I dont know why.

          1 Reply Last reply
          0
          • R Offline
            R Offline
            Redman
            wrote on last edited by
            #5

            I found the issue. The application that uses the library calls connect(...) on the signal I was talking about. I found out after commenting the whole Receiver class that the programm still worked, thus declaring Receiver class useless.

            1 Reply Last reply
            0
            • R Redman has marked this topic as solved on
            • D Offline
              D Offline
              Dgcustomer
              wrote on last edited by
              #6

              @jsulm said in Signal handling with uninitialized receiver:

              ClassFoo then emits a signal.

              Meaning Qt signal, are you?
              Only instances of classes are capable of receiving Qt signals. In order to connect the sender and receiver, there must be a ClassReceiver instance someplace and a connect(...) method. Look for this in the source code.
              It doesn't matter if there are no receivers connected; signals can still be sent.

              1 Reply Last reply
              0
              • Christian EhrlicherC Christian Ehrlicher locked this topic on

              • Login

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • Users
              • Groups
              • Search
              • Get Qt Extensions
              • Unsolved