Object :: connect: no such signal

I am having a problem creating custom slots / signals with structure. I have the following code:

qRegisterMetaType<namespace::myClassA::aStruct>();
QObject::connect(&myClassA, SIGNAL(theSignal(myClassA::aStruct)),
                  &myClassB, SLOT(theSlot(myClassA::aStruct)));

      

When running the program, I got:

Object::connect: No such signal NameSpace::myClassA::theSignal(myClassA::aStruct)
Object::connect:  (receiver name: 'NameSpace__CLASSNAME')

      

How to solve this problem?

PS: The slot and signal were correctly declared in the Q_SIGNALS and Q_SLOTS header files with the correct argument (aStruct)

+3


source to share


3 answers


The types used in signal / slot connections must be completely "copied" because the method call is converted to text, so your connection call should look like this:

QObject::connect(&myClassA, SIGNAL(theSignal(namespace::myClassA::aStruct)),
                 &myClassB, SLOT(theSlot(namespace::myClassA::aStruct)));

      



You may have to update the signal / slot declaration arguments to match.

+8


source


I found a signal slot solution: Declaring and calling signal and slot functions are incompatible! Once I fixed them, the slot got its name.

You can get all possible ways of error here.



20 Ways to Debug Qt Signals and Slots

Hope it helped a lot after reading this article and saves you some time.

+1


source


When you declare slot / signals, you can base the argument structure namespaces like this:

:: names :: ClassA :: structA

Instead of using ClassA :: structA from within 'namespace'. This is useful if you are trying to reference a struct within the same namespace.

0


source







All Articles