Search code examples
qtsignals-slotsqobject

Object::connect: No such signal


I have a problem to create custom slots/signal with a struct. 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 do I resolve this problem?

PS: The slot and the signal have been properly declared in header files using the Q_SIGNALS and Q_SLOTS keywords, with the correct argument (aStruct).


Solution

  • Types used in signal/slot connections must be fully 'scoped' because the method call is converted into text, so your connection call should look like this:

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

    You'll probably have to update the signal/slot declaration arguments to match.