Error: undefined reference to 'vtable for TimeGraphics'



  • Error: undefined reference to 'vtable for TimeGraphics'
    This class can handle signals and slots and it has a slot called timeWidget_ticker
    which is connected to a timer, which means once in a while this function would be called. This function will tick QLabel

    '''
    class TimeGraphics: public QObject, public QGraphicsRectItem{
    Q_OBJECT
    public:
    TimeGraphics();
    public slots:
    void timeWidget_ticker();
    private:
    QLabel* timeWidget;
    };

    '''
    TimeGraphics::TimeGraphics()
    {

    QLabel *timeWidget = new QLabel;
    timeWidget->setStyleSheet("QLabel {color:white;}");
    QTimer *systemTimer1 = new QTimer(this);
    connect(systemTimer1,SIGNAL(timeout()), this, SLOT(timeWidget_ticker));
    systemTimer1->start();
    

    }

    void TimeGraphics::timeWidget_ticker()
    {
    QTime time = QTime::currentTime();
    QString time_text = time.toString("hh : mm : ss");
    if (time.second() % 2 == 0)
    {
    time_text[3]= ' ';
    time_text[8]= ' ';
    }
    timeWidget->setText(time_text);
    }



  • It is solved after running qmake and clean.
    But i can't create object onto Graphics with the code below

    '''
    TimeGraphics *timerWidget = new TimeGraphics();
    scene.addItem(timerWidget);


  • Lifetime Qt Champion

    Hi,

    What do you mean by "can't create" ? What your expecting ? What are you getting ?


Log in to reply
 

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