No such signal in QT4
I have a signal and a slot that should fit together quite nicely.
class MemberVisitor: public QObject
{
Q_OBJECT
signals:
void processMember(Member* member, bool &breakLoop);
public:
void processList(QList<Member*>* list);
};
along with:
class MemberFinder: public QObject
{
Q_OBJECT
public slots:
void processMember(Member* member, bool &breakLoop);
public:
Member* member();
MemberFinder(QString memID): m_member(0), m_memID(memID) {};
private:
Member* m_member;
QString m_memID;
};
Not exactly complex, right? But I am definitely missing something, because QT keeps giving me the error: "Object::connect: No such signal MemberVisitor::processMember() in OperationsOnMembers.cpp:29"
Here's the code that should be hooking them up:
QObject::connect(visitor, SIGNAL(processMember()), finder, SLOT(processMember()));
I've also tried all the reasonable alternatives, like calling the function o开发者_JS百科n finder. But I keep getting the same problem. What am I missing?
The call to connect()
should be:
QObject::connect(visitor, SIGNAL(processMember(Member*, bool&)),
finder, SLOT(processMember(Member*, bool&)));
..provided that visitor and finder are pointers.
You need to include the parameter types (but not the parameter names) in the QObject::connect() call. e.g.
QObject::connect(visitor, SIGNAL(processMember(Member*, bool&)), finder, SLOT(processMember(Member*, bool&)));
That also lets you overload signals and slots, so you can emit signals with the same name but different parameters (same as overloading of a function, which is basically what a slot is).
This also lets you connect a signal to a slot that has fewer parameters. If your Member finder had a second slot as such :
class MemberFinder: public QObject
{
Q_OBJECT
public slots:
void processMember(Member* member, bool &breakLoop);
void processMember(Member* member);
public:
Member* member();
MemberFinder(QString memID): m_member(0), m_memID(memID) {};
private:
Member* m_member;
QString m_memID;
};
You could connect the same signal to the second slot as such :
QObject::connect(visitor, SIGNAL(processMember(Member*, bool&)), finder, SLOT(processMember(Member*)));
精彩评论