Results 1 to 3 of 3

Thread: Isn't event loop going to take up lot of CPU time as it is basically a while loop?

  1. #1
    Join Date
    May 2021
    Posts
    2
    Qt products
    Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default 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:


    Qt Code:
    1. while (is_active) {
    2. while (!event_queue_is_empty)
    3. dispatch_next_event();
    4. wait_for_more_events();
    5. }
    To copy to clipboard, switch view to plain text mode 

    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?

  2. #2
    Join Date
    Jan 2006
    Location
    Bremen, Germany
    Posts
    554
    Thanked 86 Times in 81 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default 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.

  3. #3
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,229
    Thanks
    302
    Thanked 864 Times in 851 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: Isn't event loop going to take up lot of CPU time as it is basically a while loop

    conceptually
    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.
    <=== The Great Pumpkin says ===>
    Please use CODE tags when posting source code so it is more readable. Click "Go Advanced" and then the "#" icon to insert the tags. Paste your code between them.

Similar Threads

  1. Replies: 4
    Last Post: 6th August 2011, 02:40
  2. Main loop thread loop communication
    By mcsahin in forum Qt Programming
    Replies: 7
    Last Post: 25th January 2011, 17:31
  3. Event loop
    By jefs in forum Qt Programming
    Replies: 2
    Last Post: 2nd January 2011, 18:51
  4. Replies: 10
    Last Post: 15th January 2010, 15:35
  5. Replies: 0
    Last Post: 23rd October 2008, 13:43

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.