How to "break_up" single methoid / function...
-
As of now I have a single (test) function / method which includes several time consuming - hardware dependent - tasks.
The "result" of this - I get GUI update AFTER all tasks are finished.I like to have GUI update AFTER EACH task is done, or at minimum - some kind of status display - located at "master GUI " after each task.
Any suggestion on how to realize this ?
-
As of now I have a single (test) function / method which includes several time consuming - hardware dependent - tasks.
The "result" of this - I get GUI update AFTER all tasks are finished.I like to have GUI update AFTER EACH task is done, or at minimum - some kind of status display - located at "master GUI " after each task.
Any suggestion on how to realize this ?
@AnneRanch said in How to "break_up" single methoid / function...:
or at minimum - some kind of status display
For this variant (and if you don't use separate threads yet) you can use a QProgressDialog (mostly helpful if you know the number of tasks beforehand). If a single task takes too long, there are tricks using
QApplication::processEvents()
. However, this will slow down each single task and is not a recommended methods. The best solution (as already suggested by @SamiV123) is to use a separate thread for the tasks, so that the GUI can stay responsive. -
@AnneRanch said in How to "break_up" single methoid / function...:
or at minimum - some kind of status display
For this variant (and if you don't use separate threads yet) you can use a QProgressDialog (mostly helpful if you know the number of tasks beforehand). If a single task takes too long, there are tricks using
QApplication::processEvents()
. However, this will slow down each single task and is not a recommended methods. The best solution (as already suggested by @SamiV123) is to use a separate thread for the tasks, so that the GUI can stay responsive.@SimonSchroeder OK, I am game to try threads. My tasks are both "system calls" and QProcess - any "gotcha" there ?
-
@SimonSchroeder OK, I am game to try threads. My tasks are both "system calls" and QProcess - any "gotcha" there ?
@AnneRanch said in How to "break_up" single methoid / function...:
My tasks are both "system calls" and QProcess - any "gotcha" there ?
Nothing comes to mind right away. Those should have no (extra) problems when used inside threads. BTW, the easiest way to use threading in Qt is by using
QtConcurrent::run(...)
. -
@AnneRanch said in How to "break_up" single methoid / function...:
My tasks are both "system calls" and QProcess - any "gotcha" there ?
Nothing comes to mind right away. Those should have no (extra) problems when used inside threads. BTW, the easiest way to use threading in Qt is by using
QtConcurrent::run(...)
.@SimonSchroeder said in How to "break_up" single methoid / function...:
BTW, the easiest way to use threading in Qt is by using QtConcurrent::run(...)
Thats a debatable opinion.
-
@SimonSchroeder said in How to "break_up" single methoid / function...:
BTW, the easiest way to use threading in Qt is by using QtConcurrent::run(...)
Thats a debatable opinion.
@J-Hilk OK, whatever I pick I still have to "split" the current function I have now, correct ?
PS.
(Almost) every time I ask similar question I get "it will slow down...". To me it is immaterial since my "process" is HARDWARE dependent, so some minor "software delay" does not matter... I just need each task to post "progress state"...PPS
Just to be on safe side, and not to break the code too much , I will "split" the last task first.... -
@J-Hilk OK, whatever I pick I still have to "split" the current function I have now, correct ?
PS.
(Almost) every time I ask similar question I get "it will slow down...". To me it is immaterial since my "process" is HARDWARE dependent, so some minor "software delay" does not matter... I just need each task to post "progress state"...PPS
Just to be on safe side, and not to break the code too much , I will "split" the last task first....@AnneRanch said in How to "break_up" single methoid / function...:
whatever I pick I still have to "split" the current function I have now, correct ?
Seems to me that it depends on what you mean by "split" - if you use the above suggestions, you can retain a single worker function that does all the HW stuff you mention. As that function makes progress, it can send signals to the main thread to update the UI. So, if I understand the use case, all the "work" can be performed within a single function.