Signal handling with uninitialized receiver
-
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 byClassReceiver()
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
-
@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. -
@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 andconnect()
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.) -
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.
-
-
@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. -
C Christian Ehrlicher locked this topic on