PDA

View Full Version : Connecting two classes with slgnal and slot



Benjamin
22nd January 2009, 12:06
Hi all,

I am trying to connect two classes with signals and slots but without any luck.

I have a formSessionList class which has FileName(QString filename) slot and FileVisitor class which has foundFile(QString filename) signal.

I create an FileVisitor object from formSessionList constructor.

FileVisitor filevisitor;

But I can not make a connection between them.

connect(filevisitor, SIGNAL(foundFile(QString filename)), this, SLOT(FileName(QString filename)));

I get this error:

no matching function for call to `formSessionList::connect(FileVisitor&, const char[29], formSessionList* const, const char[28])'

Does anyone has any idea?

Tnx,
Benjamin

jpn
22nd January 2009, 12:11
First of all, QObject::connect() takes pointers to the sender and the receiver. So if you allocate the "filevisitor" on the stack, you need to pass "&filevisitor". Secondly, you must not put parameter names inside the SIGNAL() and SLOT() macros. So probably it should be something like this:


connect(&filevisitor, SIGNAL(foundFile(QString)), this, SLOT(FileName(QString)));

Benjamin
22nd January 2009, 13:16
Tnx, it works now.