PDA

View Full Version : QT/C++ GUI misconception



Ini
21st March 2016, 15:46
I found no answer for this Problem in C++/Qt on the internet:

command1
different command
different command
different command
.
.
.
like 1000 different commands
.
.
.
different command



No Loop. How does the GUI stay responsive, while this intensive processing??? You cannot write after every command a qWait or a processEvents()

I only found answers like put a qwait there put a processEvent there and hope it works. Which it clearly does not if there is no loop around it like in my example.

Is it a misconception of C++/Qt?

Why should somebody not want responsive GUI? In this case its not possible in c++ is it?

I think my example is very clear, I hope for simple answers :)

anda_skoa
21st March 2016, 15:54
If you have a long running task that cannot be split into smaller subtasks which could be run in sequence, then you can put the into a different execution context, e.g. a thread or child process.

Cheers,
_

Ini
21st March 2016, 15:58
So I would need to continue in the thread that gives the commands to the thread where the GUI is, after painting in the GUI is done to be synchron right?

like
thread1: command paint someting in GUI thread
GUI threads paints
thread1 should continue processing only after painting finsihed

is that automatically the case? or do I need to add code for that

anda_skoa
21st March 2016, 16:57
That always depends on the task at hand.

Sometimes the long processing has a result, sometimes it has many intermediate results, it could have progress reporting or not, etc.

it always depends on the use case.

Cheers,
_

wysota
21st March 2016, 18:44
Have you read this?

https://doc.qt.io/archives/qq/qq27-responsive-guis.html