Results 1 to 3 of 3

Thread: Connecting two classes with slgnal and slot

  1. #1
    Join Date
    Dec 2007
    Posts
    36
    Thanks
    2
    Qt products
    Qt3 Qt/Embedded
    Platforms
    Unix/X11

    Default Connecting two classes with slgnal and slot

    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

  2. #2
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,518 Times in 1,388 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: Connecting two classes with slgnal and slot

    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:
    Qt Code:
    1. connect(&filevisitor, SIGNAL(foundFile(QString)), this, SLOT(FileName(QString)));
    To copy to clipboard, switch view to plain text mode 
    J-P Nurmi

  3. The following user says thank you to jpn for this useful post:

    Benjamin (22nd January 2009)

  4. #3
    Join Date
    Dec 2007
    Posts
    36
    Thanks
    2
    Qt products
    Qt3 Qt/Embedded
    Platforms
    Unix/X11

    Default Re: Connecting two classes with slgnal and slot

    Tnx, it works now.

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.