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
-
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 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 I do have !_Object added to my class declaration and yet the issue persists
-
@mcosta I do have !_Object added to my class declaration and yet the issue persists
@briantranscend
Hi
if it still persists then go to the build folder and delete all files.
then rebuild -
@mcosta I do have !_Object added to my class declaration and yet the issue persists
@briantranscend hi and welcome to devnet,
Did you re-run qmake after adding the Q_OBJECT macro ?
-
@mcosta I do have !_Object added to my class declaration and yet the issue persists
@briantranscend please take a look at the new syntax for signals & slots
It'll help you catch errors at compile time...