Digital clock (using QTimer) [SOLVED]

  • Hi all!
    I'm trying to code a simpler digital clock, adapted from the tutorial here :
    There are lots of error in the debug:
    Undefined reference to 'vtable for DigitalClock'
    Undefined reference to 'DigitalClock::StaticMetaObject'
    Undefined reference to 'qMain(int, char**)'
    collect 2: id returned 1 exit status

    Here's the code :

    @#include <QApplication>
    #include <QDateTime>
    #include <QLabel>
    #include <QTimer>

    class DigitalClock : public QLabel

    DigitalClock(QWidget *parent = 0);

    private slots:
    void showTime();

    DigitalClock::DigitalClock(QWidget *parent)
    : QLabel(parent)
    QTimer *timer = new QTimer(this);
    connect(timer, SIGNAL(timeout()), this, SLOT(showTime()));

     setWindowTitle(tr("Digital Clock"));
     resize(150, 60);


    void DigitalClock::showTime()
    QDateTime time = QDateTime::currentDateTime();
    QString text = time.toString();

  • Did you use their included main.cpp? It doesn't look like they included a .pro file - did you use qmake to configure before you tried to build?

  • Fairly often these problems occur if something is not correctly included, check your .pro file for errors and if you have a main... well if you even use a main function, it would help if you would show the whole code.


Log in to reply

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