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
Qt 6.11 is out! See what's new in the release blog

Manual loop

Scheduled Pinned Locked Moved Unsolved General and Desktop
6 Posts 4 Posters 2.0k 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
    Mehodin
    wrote on 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()

    aha_1980A 1 Reply Last reply
    0
    • sierdzioS Offline
      sierdzioS Offline
      sierdzio
      Moderators
      wrote on 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 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

        sierdzioS J.HilkJ 2 Replies Last reply
        0
        • M Mehodin

          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

          sierdzioS Offline
          sierdzioS Offline
          sierdzio
          Moderators
          wrote on 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

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

            aha_1980A Offline
            aha_1980A Offline
            aha_1980
            Lifetime Qt Champion
            wrote on 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

              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.HilkJ Offline
              J.HilkJ Offline
              J.Hilk
              Moderators
              wrote on 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

              • Login

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