Results 1 to 3 of 3

Thread: QTimer class and timeout() signal and slot not connecting

  1. #1
    Join Date
    Sep 2009
    Posts
    60
    Thanks
    6
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default QTimer class and timeout() signal and slot not connecting

    I have a widget:
    Qt Code:
    1. //foo.h
    2. #include <QTimer>
    3. ...
    4.  
    5. class foo : public QWidget
    6. {
    7. ...
    8. private slots:
    9. void on_timer_timeout();
    10. ...
    11. private:
    12. QTimer *timer;
    13. ...
    14. }
    To copy to clipboard, switch view to plain text mode 
    and
    Qt Code:
    1. //foo.cpp
    2. #include "foo.h"
    3. foo::foo(QWidget *parent)
    4. : QWidget(parent)
    5. {
    6. ...
    7. timer = new QTimer(this);
    8. timer->start(5);
    9. ...
    10. }
    11.  
    12. void foo::on_timer_timeout()
    13. {
    14. //do stuff
    15. }
    To copy to clipboard, switch view to plain text mode 
    When I run the program that creates the widget foo, I get the error:
    QMetaObject::connectSlotsByName: No matching signal for on_timer_timeout().

    What is the problem?
    Last edited by di_zou; 8th September 2009 at 21:17.

  2. #2
    Join Date
    Mar 2007
    Location
    Germany
    Posts
    229
    Thanks
    2
    Thanked 29 Times in 28 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QTimer class and timeout() signal and slot not connecting

    Don't you miss a line like this?
    Qt Code:
    1. connect( timer, SIGNAL(timeout()), SLOT(on_timer_timeout()) );
    To copy to clipboard, switch view to plain text mode 
    How shall the program know what to call when the signal timeout() is emitted?
    And I have no idea what to do with you error message.

  3. #3
    Join Date
    Jan 2008
    Location
    Poland
    Posts
    687
    Thanks
    4
    Thanked 140 Times in 132 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: QTimer class and timeout() signal and slot not connecting

    the:
    Qt Code:
    1. void on_xxx_yyy();
    To copy to clipboard, switch view to plain text mode 
    slots works fine but the xxx is not a C++ variable name but the object name (QObject::objectName(), QObject::setObjectName()), and didn't set any object name to your timer. So better do it in standard way, it means connect slot with signal manualy:
    Qt Code:
    1. private slots:
    2. void myTimeoutSlot();
    3. private:
    4. QTimer *timer;
    To copy to clipboard, switch view to plain text mode 
    Qt Code:
    1. . . .
    2. connect(timer, SIGNAL(timeout()), this, SLOT(myTimeoutSlot()));
    3. . . .
    To copy to clipboard, switch view to plain text mode 
    I would like to be a "Guru"

    Useful hints (try them before asking):
    1. Use Qt Assistant
    2. Search the forum

    If you haven't found solution yet then create new topic with smart question.

  4. The following user says thank you to faldzip for this useful post:

    di_zou (9th September 2009)

Similar Threads

  1. QTimer in QThread doesn't start or timeout
    By Boron in forum Qt Programming
    Replies: 9
    Last Post: 21st October 2011, 13:51
  2. Replies: 3
    Last Post: 15th April 2007, 19:16
  3. QTimer problem ... it runs but never triggs
    By yellowmat in forum Newbie
    Replies: 4
    Last Post: 4th July 2006, 12:54

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.