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. QDialog showing busy while loop is running

QDialog showing busy while loop is running

Scheduled Pinned Locked Moved Unsolved General and Desktop
5 Posts 4 Posters 481 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
    mikael.larsson
    wrote on last edited by
    #1

    I have a problem figuring out how I should solve my problem.
    I made my own QDialog which I execute open() on.
    And then run my while loop, the problem is that this way the QDialog is black/transparent in the cases I've tried.

    I want it to run and show a Cancel button with a spinning indiator while my loop is running.
    Therefore .exec() isn't the solution since then it wouldn't run my loop.

    QDialog dlg
    dlg.show();
    
    while (true) {
     //do stuff
    }
    

    What would be the best solution here?

    1 Reply Last reply
    0
    • Christian EhrlicherC Offline
      Christian EhrlicherC Offline
      Christian Ehrlicher
      Lifetime Qt Champion
      wrote on last edited by
      #2

      @mikael-larsson said in QDialog showing busy while loop is running:

      What would be the best solution here?

      Don't block the event loop. What are you doing in your while loop?

      Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
      Visit the Qt Academy at https://academy.qt.io/catalog

      M 1 Reply Last reply
      2
      • S Offline
        S Offline
        stryga42
        wrote on last edited by
        #3

        Never run "endless" loops (anything which takes longer than the blink of your eyes) in your GUI thread. This will freeze your GUI. Either you can split your do-stuff-task in small chunks - then you can pack it in a QTimer callback and start the timer with zero delay - or you have to learn true multi threading. See for example https://doc.qt.io/qt-5/threads-technologies.html as a starting point.

        1 Reply Last reply
        1
        • Christian EhrlicherC Christian Ehrlicher

          @mikael-larsson said in QDialog showing busy while loop is running:

          What would be the best solution here?

          Don't block the event loop. What are you doing in your while loop?

          M Offline
          M Offline
          mikael.larsson
          wrote on last edited by
          #4

          @Christian-Ehrlicher running an external program where I wait for it to finish.

          I was hoping theere would be an easy solution, if I had any progress I could just have ran QProgressDialog but since I have no indication on how far the progress have come I'm stuck with just saying that the program is running.

          jsulmJ 1 Reply Last reply
          0
          • M mikael.larsson

            @Christian-Ehrlicher running an external program where I wait for it to finish.

            I was hoping theere would be an easy solution, if I had any progress I could just have ran QProgressDialog but since I have no indication on how far the progress have come I'm stuck with just saying that the program is running.

            jsulmJ Online
            jsulmJ Online
            jsulm
            Lifetime Qt Champion
            wrote on last edited by
            #5

            @mikael-larsson said in QDialog showing busy while loop is running:

            running an external program where I wait for it to finish

            There is no reason to "wait" for it to finish - there is https://doc.qt.io/qt-5/qprocess.html#finished signal.

            https://forum.qt.io/topic/113070/qt-code-of-conduct

            1 Reply Last reply
            4

            • Login

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