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. GUI does not update when standard C++ file operation takes place

GUI does not update when standard C++ file operation takes place

Scheduled Pinned Locked Moved Unsolved General and Desktop
qwidgetupdateqprogressbardesktop
7 Posts 3 Posters 3.5k 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.
  • K Offline
    K Offline
    kzarog
    wrote on 21 Oct 2015, 10:30 last edited by kzarog
    #1

    Hello all,

    I am having the following issue; the GUI I have built does not update when a standard C++ operation takes place.

    I want to have a QProgressBar that continuously moves (since I do not know how long it will take) until the file import is completed. The QProgressBar is notified by a signal to initiate and end its animation. However, the progress bar is never seen in action by the user. Debugging the program confirms that everything works as intended but the GUI does not update while the file import operation takes place, behaving as a bottleneck. Updating the widgets using update() does not help.

    Is this working as intended? Any pointers on how I could resolve this? If possible, I would not want to move the file operation onto a new thread.

    Thank you in advance!

    M 1 Reply Last reply 21 Oct 2015, 11:12
    0
    • S Offline
      S Offline
      sneubert
      wrote on 21 Oct 2015, 11:01 last edited by
      #2

      Hi kzargo,

      as long as there´s a blocking function call in your applications main thread the gui won´t update. You can either use async operations or creat a thread.

      1 Reply Last reply
      0
      • K kzarog
        21 Oct 2015, 10:30

        Hello all,

        I am having the following issue; the GUI I have built does not update when a standard C++ operation takes place.

        I want to have a QProgressBar that continuously moves (since I do not know how long it will take) until the file import is completed. The QProgressBar is notified by a signal to initiate and end its animation. However, the progress bar is never seen in action by the user. Debugging the program confirms that everything works as intended but the GUI does not update while the file import operation takes place, behaving as a bottleneck. Updating the widgets using update() does not help.

        Is this working as intended? Any pointers on how I could resolve this? If possible, I would not want to move the file operation onto a new thread.

        Thank you in advance!

        M Offline
        M Offline
        mrjj
        Lifetime Qt Champion
        wrote on 21 Oct 2015, 11:12 last edited by
        #3

        @kzarog
        A thread sounds like good idea.
        You could also try with QApplication::processEvents()
        but its not good design and should be used only for a quick fix /testing.

        1 Reply Last reply
        0
        • K Offline
          K Offline
          kzarog
          wrote on 21 Oct 2015, 11:21 last edited by
          #4

          @sneubert , @mrjj Thank you both for your replies!

          QApplication::processEvents() seems to not be working, unfortunately.

          It seems that threading is the way to go with this one... Would you recommend my using of the QThread or maybe the QtConcurrent approach?

          Again, thank you for your help!

          M 1 Reply Last reply 21 Oct 2015, 11:27
          0
          • K kzarog
            21 Oct 2015, 11:21

            @sneubert , @mrjj Thank you both for your replies!

            QApplication::processEvents() seems to not be working, unfortunately.

            It seems that threading is the way to go with this one... Would you recommend my using of the QThread or maybe the QtConcurrent approach?

            Again, thank you for your help!

            M Offline
            M Offline
            mrjj
            Lifetime Qt Champion
            wrote on 21 Oct 2015, 11:27 last edited by
            #5

            @kzarog said:
            Well if the reading takes a long time,
            processEvent does nothing for you.

            well I vote for QtConcurrent just because I found it easy to get up and running
            http://doc.qt.io/qt-5/qtconcurrent-runfunction-example.html

            but if its the best solution to your task, I dont know.

            1 Reply Last reply
            0
            • S Offline
              S Offline
              sneubert
              wrote on 21 Oct 2015, 11:28 last edited by sneubert
              #6

              QTConcurrent::run is easier to use but you cant cancle the operation or be sure your function is running immediately. So where finere control is neccesary use QThread

              1 Reply Last reply
              1
              • K Offline
                K Offline
                kzarog
                wrote on 21 Oct 2015, 11:45 last edited by
                #7

                Thank you for your answers, I will look into both QThread and QtConcurrent.

                1 Reply Last reply
                0

                1/7

                21 Oct 2015, 10:30

                • Login

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