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. [SOLVED]QTimer locks my app
QtWS25 Last Chance

[SOLVED]QTimer locks my app

Scheduled Pinned Locked Moved General and Desktop
9 Posts 3 Posters 2.1k Views
  • 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 Offline
    B Offline
    b1gsnak3
    wrote on last edited by
    #1

    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
    0
    • A Offline
      A Offline
      andre
      wrote on last edited by
      #2

      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
      0
      • Q Offline
        Q Offline
        qxoz
        wrote on last edited by
        #3

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

        1 Reply Last reply
        0
        • Q Offline
          Q Offline
          qxoz
          wrote on last edited by
          #4

          [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
          0
          • A Offline
            A Offline
            andre
            wrote on last edited by
            #5

            [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
            0
            • Q Offline
              Q Offline
              qxoz
              wrote on last edited by
              #6

              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
              0
              • A Offline
                A Offline
                andre
                wrote on last edited by
                #7

                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
                0
                • Q Offline
                  Q Offline
                  qxoz
                  wrote on last edited by
                  #8

                  Thanks Andre :)

                  1 Reply Last reply
                  0
                  • B Offline
                    B Offline
                    b1gsnak3
                    wrote on last edited by
                    #9

                    Thank you I solved using the timeout signal.

                    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