Isn't event loop going to take up lot of CPU time as it is basically a while loop?
From this official Qt documentation event loop conceptually executes as follows:
Code:
while (is_active) {
while (!event_queue_is_empty)
dispatch_next_event();
wait_for_more_events();
}
As one can observe that Qt application will utilise the CPU all the time as it needs to keep running the loop for its GUI to be updated. If this is the case what happens when multiple threads run concurrently in addition to GUI thread? Will the performance degrade while multi tasking?
Re: Isn't event loop going to take up lot of CPU time as it is basically a while loop
Did you see that a simple Qt application which simply runs an event loop take 100% of a CPU? Me not. So you assumption is wrong.
Re: Isn't event loop going to take up lot of CPU time as it is basically a while loop
This is the key word in that phrase. The GUI thread is like any other thread running in your PC's operating system. If it goes idle waiting for input, it will be suspended so that other active threads can run. The only way the Qt GUI thread will lock up your program (but not your PC) is if you implement such a loop (or use a blocking function) yourself and never let control return to the Qt event loop.