QObject::connect: No such slot QWidget::showTimee()



  • My error:
    QObject::connect: No such slot QWidget::showTimee() in ../TUecomotivefinal/digitalclock.cpp:11

    digitalclock.h:

    #ifndef DIGITALCLOCK_H
    #define DIGITALCLOCK_H
    #include <QWidget>
    class DigitalClock : public QWidget
    {
    public:
        DigitalClock(QWidget *parent = 0);
    public slots:
        void showTimee();
    private:
    };
    #endif // DIGITALCLOCK_H
    

    digitalclock.cpp

    #include "digitalclock.h"
    #include <QDebug>
    #include <QtWidgets>
    #include <QObject>
    DigitalClock::DigitalClock(QWidget *parent)
        : QWidget(parent)
    {
        QTimer *timer2 = new QTimer(this);
        QObject::connect(timer2, SIGNAL(timeout()), this, SLOT(showTimee()));
        timer2->start(10000);
    }
    void DigitalClock::showTimee(){
            QTime time = QTime::currentTime();
            QString text = time.toString("hh:mm");
            qDebug() << text;
    }
    

    I am kind of new to C++ and new to QT.. I'm hoping someone can help. Thanks in advance!



  • Hi,

    you have to add Q_OBJECT in your class declaration

    #ifndef DIGITALCLOCK_H
    #define DIGITALCLOCK_H
    #include <QWidget>
    class DigitalClock : public QWidget
    {
        Q_OBJECT
    
    public:
        DigitalClock(QWidget *parent = 0);
    public slots:
        void showTimee();
    private:
    };
    #endif // DIGITALCLOCK_H
    


  • @mcosta
    Nice! This solved it!
    Can you explain why I need to set this?
    Knowing the solution is one, but understanding is more important ;p



  • Hi,
    the Q_OBJECT macro is used to tell the MOC (meta object compiler) that a particular class uses Qt's signals and slots mechanism.



  • Hi,

    you can found more information here and here


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.