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
Forum Updated to NodeBB v4.3 + New Features

QDialog showing busy while loop is running

Scheduled Pinned Locked Moved Unsolved General and Desktop
5 Posts 4 Posters 525 Views 2 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
    mikael.larsson
    wrote on 4 Dec 2020, 15:57 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
    • C Offline
      C Offline
      Christian Ehrlicher
      Lifetime Qt Champion
      wrote on 4 Dec 2020, 16:37 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 7 Dec 2020, 08:28
      2
      • S Offline
        S Offline
        stryga42
        wrote on 4 Dec 2020, 17:18 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
        • C Christian Ehrlicher
          4 Dec 2020, 16:37

          @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 7 Dec 2020, 08:28 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.

          J 1 Reply Last reply 7 Dec 2020, 08:30
          0
          • M mikael.larsson
            7 Dec 2020, 08:28

            @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.

            J Offline
            J Offline
            jsulm
            Lifetime Qt Champion
            wrote on 7 Dec 2020, 08:30 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

            1/5

            4 Dec 2020, 15:57

            • Login

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