Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Digital clock (using QTimer) [SOLVED]
Forum Updated to NodeBB v4.3 + New Features

Digital clock (using QTimer) [SOLVED]

Scheduled Pinned Locked Moved General and Desktop
3 Posts 3 Posters 3.0k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • P Offline
    P Offline
    Philili
    wrote on last edited by
    #1

    Hi all!
    I'm trying to code a simpler digital clock, adapted from the tutorial here : http://doc.qt.nokia.com/4.2/widgets-digitalclock.html
    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
    {
    Q_OBJECT

    public:
    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()));
    timer->start(1000);

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

    }

    void DigitalClock::showTime()
    {
    QDateTime time = QDateTime::currentDateTime();
    QString text = time.toString();
    show();
    }
    @
    thanks!

    1 Reply Last reply
    0
    • D Offline
      D Offline
      daviddoria
      wrote on last edited by
      #2

      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?

      1 Reply Last reply
      0
      • 0 Offline
        0 Offline
        010110102
        wrote on last edited by
        #3

        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.

        cheers

        1 Reply Last reply
        0

        • Login

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved