Signal/Slot clarification [SOLVED]
Is the signal/slot pair working like a callback mechanism? If I want to create a custom pair signal/slot can I pass as parameter every kind of object? Is this wrong?
thanks in advance
Any type of parameter within the C++ library is possible. Even user defined structures etc. It is just a special way to call (member) functions automatically when a event occurs. So any class can create a signal an can be paired to a slot.
Might be a good suggestion to read the signal/slot information before venturing into this part of coding. Isn't all that difficult to understand.
thank you for the answer. I have the following code:
@void mySlot(const std::list<MyClass*> &);
MyManager::mySlot(const std::list<MyClass*> &theList)
std::cout << "mySlot " << std::endl;
void mySignal(const std::list<MyClass*> &theList);
TestThread ::TestThread (std::list<MyClass*>&theList, QObject *parent)
: QThread(parent), myList(theList)
@QObject::connect(threadObj, SIGNAL(mySignal(std::list<MyClass*>)), this, SLOT(mySlot(std::list<MyClass*>)));@
the slot is never fired. What's wrong?
[quote author="blackbelt" date="1343654430"]Is the signal/slot pair working like a callback mechanism? If I want to create a custom pair signal/slot can I pass as parameter every kind of object? Is this wrong?
thanks in advance[/quote]
It's more like publisher/subscriber pattern. You can have any number of slots being connected to one signal.
QObject::connect prints a qDebug message when signal-slot-connection fails. Do you see such a message in debug mode?
If not: Is the connection made before emitting the signal?
And finally: Try not to mix Qt and STL when not absolutely necessary. For example, use QList or QLinkedList instead of std::list.
Signal-slot connections between threads have some more restrictions than the normal, direct ones. That is because the mechanism needs to be able to serialize and deserialize the data. I note from your code that you seem to be using multiple threads.
Did you register your type to the [[doc:QMetaType]] system?
Yes, register the QMetaType did the trick . Thank you