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] Wait for timeout or some signal
Forum Updated to NodeBB v4.3 + New Features

[SOLVED] Wait for timeout or some signal

Scheduled Pinned Locked Moved General and Desktop
16 Posts 7 Posters 28.5k Views 1 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.
  • M Offline
    M Offline
    maxim.prishchepa
    wrote on last edited by
    #3

    WOW so easy? i'll try that :) thnx

    Programming Is Like Sex: One mistake and you have to support it for the rest of your life. (Michael Sinz).

    1 Reply Last reply
    0
    • sierdzioS Offline
      sierdzioS Offline
      sierdzio
      Moderators
      wrote on last edited by
      #4

      Yeah, it forces the QCoreApplication instance to process events in the event queue, including signals and slots provided by MOC. This way, the loop does not block operation of the app.

      (Z(:^

      1 Reply Last reply
      0
      • M Offline
        M Offline
        maxim.prishchepa
        wrote on last edited by
        #5

        tnx, i note that!

        Programming Is Like Sex: One mistake and you have to support it for the rest of your life. (Michael Sinz).

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

          Or, look into "QxtSignalWaiter":http://libqxt.bitbucket.org/doc/0.6/qxtsignalwaiter.html from the libQxt library.

          1 Reply Last reply
          0
          • M Offline
            M Offline
            maxim.prishchepa
            wrote on last edited by
            #7

            tnx a lot!

            Programming Is Like Sex: One mistake and you have to support it for the rest of your life. (Michael Sinz).

            1 Reply Last reply
            0
            • R Offline
              R Offline
              rich
              wrote on last edited by
              #8

              Please don't use processEvents() like this, or your CPU usage will be terrible. Instead use QEventLoop.

              1 Reply Last reply
              0
              • J Offline
                J Offline
                joonhwan
                wrote on last edited by
                #9

                @rich,
                Can hear more details of using processEvents() and QEventLoop story here?

                joonhwan at gmail dot com

                1 Reply Last reply
                0
                • A Offline
                  A Offline
                  andre
                  wrote on last edited by
                  #10

                  Calling processEvents() in a loop like proposed will keep your CPU 100% bussy, because you just keep polling the event queue. Using an eventloop is a smarter solution that doesn't waste CPU cycles like that, so it will not spike your CPU. It is also the solution implemented by the libQxt in QxtSignalWaiter.

                  1 Reply Last reply
                  0
                  • J Offline
                    J Offline
                    joonhwan
                    wrote on last edited by
                    #11

                    @Andre,
                    Thanks, feel like got good things to know and even another useful-looking library!

                    joonhwan at gmail dot com

                    1 Reply Last reply
                    0
                    • R Offline
                      R Offline
                      RomaHagen
                      wrote on last edited by
                      #12

                      QxtSignalWaiter is implemented with a help of processEvents, not eventLoop. See "here":http://dev.libqxt.org/libqxt/src/21ea5919eabb2a404eafdffcdb8383472ca66bdd/src/core/qxtsignalwaiter.cpp?at=master#cl-143.

                      1 Reply Last reply
                      0
                      • A Offline
                        A Offline
                        andre
                        wrote on last edited by
                        #13

                        [quote author="RomaHagen" date="1357227120"]QxtSignalWaiter is implemented with a help of processEvents, not eventLoop. See "here":http://dev.libqxt.org/libqxt/src/21ea5919eabb2a404eafdffcdb8383472ca66bdd/src/core/qxtsignalwaiter.cpp?at=master#cl-143. [/quote]

                        Hmmm... You're right. Surprising. Thanks for the correction.

                        Does anyone know why Qxt choose this implementation instead?

                        1 Reply Last reply
                        0
                        • R Offline
                          R Offline
                          RomaHagen
                          wrote on last edited by
                          #14

                          See "this":http://dev.libqxt.org/libqxt/src/21ea5919eabb2a404eafdffcdb8383472ca66bdd/src/core/qxtsignalwaiter.cpp?at=master#cl-143 and read the doc about WaitForMoreEvents "here":http://qt-project.org/doc/qt-4.8/qeventloop.html#ProcessEventsFlag-enum.

                          1 Reply Last reply
                          0
                          • A Offline
                            A Offline
                            andre
                            wrote on last edited by
                            #15

                            Yes, I know where to find the sources and I know the docs, but that was not my question. I sometimes use this idea:
                            @
                            QEventLoop loop;
                            connect(myObject, SIGNAL(theSignalToWaitFor()), &loop, SLOT(quit()));
                            connect(timeoutTimer, SIGNAL(timeout()), &loop, SLOT(quit()));
                            loop.exec(); //blocks untill either theSignalToWaitFor or timeout was fired
                            @

                            1 Reply Last reply
                            0
                            • M Offline
                              M Offline
                              Mar4eli
                              wrote on last edited by
                              #16

                              [quote author="Andre" date="1357286986"]Yes, I know where to find the sources and I know the docs, but that was not my question. I sometimes use this idea:
                              @
                              QEventLoop loop;
                              connect(myObject, SIGNAL(theSignalToWaitFor()), &loop, SLOT(quit()));
                              connect(timeoutTimer, SIGNAL(timeout()), &loop, SLOT(quit()));
                              loop.exec(); //blocks untill either theSignalToWaitFor or timeout was fired
                              @

                              [/quote]

                              thank you. it's very useful.

                              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