Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    [SOLVED]QTimer locks my app

    General and Desktop
    3
    9
    1770
    Loading More Posts
    • 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.
    • B
      b1gsnak3 last edited by

      I have something like this:

      @
      QToolButton *bla = new QToolButton();
      QPropertyAnimation *anim = new QPropertyAnimation(this, "geometry");
      anim->setDuration(300);
      anim->setvalues(...) //bla bla not important
      anim->start();
      QTimer timer;
      timer.start(5000);
      bla->setDisabled(true);
      while(timer.isActive()) {}
      buzzButton->setEnabled(true);
      @

      this is a basic snippet from my actual code... But I am pretty sure that it is from the timer. Because if I don't add it it goes perfectly.
      Thank you in advance

      Qt 4.8.4. MSVC2008 (Windows 7 x86)

      1 Reply Last reply Reply Quote 0
      • A
        andre last edited by

        Why are you introducing a busy waiting loop then?
        Instead, just connect the timeout signal of the timer to the setEnabled slot of the buzzButton

        1 Reply Last reply Reply Quote 0
        • Q
          qxoz last edited by

          I guess not timer locks your app
          change code it like this:
          @while(timer.isActive())
          {
          qApp->processEvents(QEventLoop::ExcludeUserInputEvents);
          }
          @

          1 Reply Last reply Reply Quote 0
          • Q
            qxoz last edited by

            [quote author="Andre" date="1359620982"]Instead, just connect the timeout signal of the timer to the setEnabled slot of the buzzButton[/quote]
            It depends from goals. If b1gsnak3 need a function which should return some value after finishing his work then busy waiting loop is applicable, but for other ways ofcourse timeout timer is more prefered.

            1 Reply Last reply Reply Quote 0
            • A
              andre last edited by

              [quote author="qxoz" date="1359621458"]If b1gsnak3 need a function which should return some value after finishing his work then busy waiting loop is applicable, but for other ways ofcourse timeout timer is more prefered.
              [/quote]

              In my opinion, busy looping in a GUI thread is (almost) never acceptable. I don't think promoting it is a good idea.

              1 Reply Last reply Reply Quote 0
              • Q
                qxoz last edited by

                I am agree with you, but, what alternative can be used in function like this?:
                @QString getRemoteId(QString login, QString pass);@
                function should connect with server via tcp and return result to main programm.

                1 Reply Last reply Reply Quote 0
                • A
                  andre last edited by

                  You'd replace it by an asynchronous call. Especially since the above may fail in all kinds of ways. Look to [[doc:QNetworkAccessManager]] for one possible implementation, and to [[doc:QFuture]] for another one.

                  1 Reply Last reply Reply Quote 0
                  • Q
                    qxoz last edited by

                    Thanks Andre :)

                    1 Reply Last reply Reply Quote 0
                    • B
                      b1gsnak3 last edited by

                      Thank you I solved using the timeout signal.

                      1 Reply Last reply Reply Quote 0
                      • First post
                        Last post