GUI does not update when standard C++ file operation takes place
-
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!
-
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.
-
@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. -
-
@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.htmlbut if its the best solution to your task, I dont know.
-
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 useQThread
-
Thank you for your answers, I will look into both QThread and QtConcurrent.
7/7