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. QTimer: 'TRUE' was not declared in this scope.
Forum Updated to NodeBB v4.3 + New Features

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

Scheduled Pinned Locked Moved General and Desktop
9 Posts 4 Posters 5.1k Views 2 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.
  • A Offline
    A Offline
    alvinNew
    wrote on last edited by p3c0
    #1

    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

    p3c0P 2 Replies Last reply
    0
    • A alvinNew

      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

      p3c0P Offline
      p3c0P Offline
      p3c0
      Moderators
      wrote on last edited by
      #2

      @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()));

      157

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

        @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.

        1 Reply Last reply
        0
        • A alvinNew

          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

          p3c0P Offline
          p3c0P Offline
          p3c0
          Moderators
          wrote on last edited by
          #4

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

          157

          1 Reply Last reply
          0
          • Malek_KhlifM Offline
            Malek_KhlifM Offline
            Malek_Khlif
            wrote on last edited by
            #5

            I Think that you should move w in pointer.

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

            I Love Qt <3

            1 Reply Last reply
            0
            • A Offline
              A Offline
              alvinNew
              wrote on last edited by
              #6

              Problem here is singleshot timer cannot have SLOT variable

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

              Any work around

              p3c0P 1 Reply Last reply
              0
              • A alvinNew

                Problem here is singleshot timer cannot have SLOT variable

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

                Any work around

                p3c0P Offline
                p3c0P Offline
                p3c0
                Moderators
                wrote on last edited by p3c0
                #7

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

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

                157

                1 Reply Last reply
                0
                • A Offline
                  A Offline
                  alvinNew
                  wrote on last edited by
                  #8

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

                  p3c0P 1 Reply Last reply
                  0
                  • A alvinNew

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

                    p3c0P Offline
                    p3c0P Offline
                    p3c0
                    Moderators
                    wrote on last edited by p3c0
                    #9

                    @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();
                    }
                    

                    157

                    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