QTimer: 'TRUE' was not declared in this scope.



  • Error: TRUE was not declared in this scope. From the link
    http://vision.lbl.gov/People/qyang/qt_doc/qtimer.html
    TRUE denote single-shot timer
    /////////////////////////////////////////////////////

        QWidget w;
        w.resize(1000,100);
        QLabel* label = new QLabel("Hello World", &w);
        w.show();
        timerMove = new QTimer(this);
        QObject::connect(timerMove, SIGNAL(timeout()),SLOT(move(label)));
        timerMove->start(1200, TRUE);
    ////////////////////////////////////////////////////////
    void MainWindow::move(QWidget* widget)
    {
        auto animation = new QPropertyAnimation(widget,"geometry");
        connect(animation,&QPropertyAnimation::finished,animation, &QPropertyAnimation::deleteLater);
    
        animation->setDuration(8000);
        //x set as 80
        animation->setStartValue(QRect(0,500,90,30));
        animation->setEasingCurve(QEasingCurve::Linear);
        //pause duaration(3s) divides by total duration(8s)
        animation->setKeyValueAt(0.375, QRect(460,500,90,30));
         //total duration minus pause duaration divides by total duration
        animation->setKeyValueAt(0.625, QRect(460,500,90,30));
        animation->setEndValue(QRect(920,500,90,30));
        animation->start();
    
    }
    

    Edited: Use ``` (3 backticks) for code blocks - p3c0


  • Moderators

    @alvinNew Which Qt version are you using ? I guess the link that you posted shows docs of old Qt version may be Qt3. Qt5's QTimer classes dont have that method. Check here for more info. You can set singleShot to true using setSingleShot to activate it once. Or use static one QTimer::singleShot(600000, &app, SLOT(quit()));



  • @alvinNew said:

    QObject::connect(timerMove, SIGNAL(timeout()),SLOT(move(label)));

    Additionally, the above connect statement is also wrong, the function arguments in the receiver SLOT can be less than or equal to sender SIGNAL. Qt can ignore arguments, but not create values from nothing.


  • Moderators

    @alvinNew Also it has to be true and not TRUE.



  • I Think that you should move w in pointer.

    QWidget w; ===> QWidget *w = new QWidget



  • Problem here is singleshot timer cannot have SLOT variable

    QTimer::singleShot(15000,this,&MainWindow:: move (label) ;

    Any work around


  • Moderators

    @alvinNew With c++11 and lambda expressions you can call a function or a slot

    QTimer::singleShot(15000,[=]() {
            move(label);
       }
    );
    


  • I tried it before.
    Error: The program has unexpectedly finished.


  • Moderators

    @alvinNew Where did it crashed exactly ? In the meantime try out the following:

    QLabel *label = new QLabel(this);
    label->setStyleSheet("background-color: red");
    
    QTimer::singleShot(1000,[=]() {
        move(label);
       }
    );
    
    void Dialog::move(QWidget* widget)
    {
        auto animation = new QPropertyAnimation(widget,"geometry");
        connect(animation,&QPropertyAnimation::finished,animation, &QPropertyAnimation::deleteLater);
        animation->setDuration(8000);
        animation->setStartValue(QRect(widget->rect()));
        animation->setEndValue(QRect(0,0,widget->width()+200,widget->height()+200));
        animation->start();
    }
    

Log in to reply
 

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