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. Manual loop

Manual loop

Scheduled Pinned Locked Moved Unsolved General and Desktop
6 Posts 4 Posters 917 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.
  • M Offline
    M Offline
    Mehodin
    wrote on 15 Jun 2019, 12:52 last edited by
    #1

    Hello,

    I was wondering whether it's possible to manually call everything that QApplication::exec() calls in a loop myself.
    For example:

    void main_loop() {
        MyOwnApp::DoAThing();
        QApplication::draw();
        QApplication::pollEvents();
        MyOwnApp::DoSomething();
    }
    

    Rather than having to use QApplication::exec() or run()

    A 1 Reply Last reply 15 Jun 2019, 16:25
    0
    • S Offline
      S Offline
      sierdzio
      Moderators
      wrote on 15 Jun 2019, 13:26 last edited by
      #2

      That's quite a deep question :-) If you don't get any answers here, consider asking on Qt interest mailing list. Qt core devs reside there and they should be able to help you. https://lists.qt-project.org/listinfo/interest

      I'll start by saying that I don't know the answer. What follows are my guesses. I think that it likely won't work - QCoreApplication is a singleton, and user code can call processEvents() at any point, which would go around your custom loop. You may have more luck if you handle events yourself in a custom event dispatcher. See setEventDispatcher() and QAbstractEventDispatcher.

      (Z(:^

      1 Reply Last reply
      1
      • M Offline
        M Offline
        Mehodin
        wrote on 15 Jun 2019, 13:42 last edited by
        #3

        I uhh, i actually managed to find what i need by simply calling QApplication::processEvents() in a while loop, somehow that was enough so the UI would keep running and wouldn't deadlock

        S J 2 Replies Last reply 15 Jun 2019, 13:44
        0
        • M Mehodin
          15 Jun 2019, 13:42

          I uhh, i actually managed to find what i need by simply calling QApplication::processEvents() in a while loop, somehow that was enough so the UI would keep running and wouldn't deadlock

          S Offline
          S Offline
          sierdzio
          Moderators
          wrote on 15 Jun 2019, 13:44 last edited by
          #4

          @Mehodin said in Manual loop:

          QApplication::processEvents()

          Please note that using this method can be quite dangerous at times. It's better, if you can, to spin a custom QEventLoop, use QThread or make your code asynchronous (based on signals and slots).

          (Z(:^

          1 Reply Last reply
          4
          • M Mehodin
            15 Jun 2019, 12:52

            Hello,

            I was wondering whether it's possible to manually call everything that QApplication::exec() calls in a loop myself.
            For example:

            void main_loop() {
                MyOwnApp::DoAThing();
                QApplication::draw();
                QApplication::pollEvents();
                MyOwnApp::DoSomething();
            }
            

            Rather than having to use QApplication::exec() or run()

            A Offline
            A Offline
            aha_1980
            Lifetime Qt Champion
            wrote on 15 Jun 2019, 16:25 last edited by
            #5

            @Mehodin You can simply use a QTimer to periodically call your user functions regularly and leave everything else standard Qt.

            Regards

            Qt has to stay free or it will die.

            1 Reply Last reply
            2
            • M Mehodin
              15 Jun 2019, 13:42

              I uhh, i actually managed to find what i need by simply calling QApplication::processEvents() in a while loop, somehow that was enough so the UI would keep running and wouldn't deadlock

              J Offline
              J Offline
              J.Hilk
              Moderators
              wrote on 15 Jun 2019, 17:22 last edited by
              #6

              @Mehodin said in Manual loop:

              I uhh, i actually managed to find what i need by simply calling QApplication::processEvents() in a while loop, somehow that was enough so the UI would keep running and wouldn't deadlock

              Please don‘t, with each call to processEvents() a fairy dies !


              Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


              Q: What's that?
              A: It's blue light.
              Q: What does it do?
              A: It turns blue.

              1 Reply Last reply
              1

              1/6

              15 Jun 2019, 12:52

              • Login

              • Login or register to search.
              1 out of 6
              • First post
                1/6
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • Users
              • Groups
              • Search
              • Get Qt Extensions
              • Unsolved