Question

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 resolved this problem?

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

Was it helpful?

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.

OTHER TIPS

I have found the solution of signal slot: The declaration and call of signal and slot functions were mismatching! As soon as I fixed them, the slot got called.

Here you may got all the possible way of mistake.

20 ways to debug Qt signals and slots

Hope, it helped a lot after reading this articlethis and will save your time.

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

::namespace::ClassA::structA

Rather than using ClassA::structA from inside 'namespace'. This is useful if you are trying to reference a structure inside the same namespace.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top