Results 1 to 9 of 9

Thread: External and Internal Event Processing in Qt

  1. #1
    Join Date
    Jul 2013
    Posts
    6
    Qt products
    Qt/Embedded
    Platforms
    Unix/X11

    Default External and Internal Event Processing in Qt

    Any GUI Framework generally blockwaits on single System call which may multiplex number of soft interfaces. But Qt has two kinds of events viz External events triggered by user through Keyboard & Mouse/Touch screen received by QSocketNotifiers and internal events triggered by QTimers.
    Both are being processed sequentially, none of them can be blocking type. Then CPU utilization should be high enough because exec call doesnt yield CPU at all. But it is verified that Qt Applications on Embedded platform is not taking so much of CPU. "select" call used by Qt is not passing NULL for timeout parameter anywhere in source code. Immediately it is looking for any timeouts of Qtimers and is repeating in while loop as long as running.

    Then how CPU utilization is fairly Low????

    Please explain me where Qt is block-waiting for or How CPU utilization is LOW enough???

  2. #2
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: External and Internal Event Processing in Qt

    I am not sure what you are asking for.

    All Qt event dispatcher implementations I had a look at had a single "select" like call, which is the one waiting for any kind of events, usually combined with a timeout to not wait indefinitely.

    For example the call in the BlackBerry event dispatcher looks like this
    Qt Code:
    1. // Wait for event or file to be ready
    2. const int result = bps_get_event(&event, timeoutLeft);
    To copy to clipboard, switch view to plain text mode 
    This call blocks until either an event of some sort occured or the timeout is reached.
    The thread calling this is suspended by the operating system until either criteria is met.
    A suspended thread does not utilize any CPU.

    Cheers,
    _

  3. #3
    Join Date
    Jul 2013
    Posts
    6
    Qt products
    Qt/Embedded
    Platforms
    Unix/X11

    Default Re: External and Internal Event Processing in Qt

    man pages of select says if timeout is zero, systemcall returns immediately.
    nowhere in code it is filled to non zero value. hence must return immediately on linux platform.
    if it returns immediately it consumes cpu cycles. but its not happening. where am i understanding wrong.

  4. #4
    Join Date
    Oct 2013
    Posts
    41
    Thanks
    1
    Thanked 8 Times in 7 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: External and Internal Event Processing in Qt

    Quote Originally Posted by vijay523201 View Post
    man pages of select says if timeout is zero, systemcall returns immediately.
    nowhere in code it is filled to non zero value. hence must return immediately on linux platform.
    if it returns immediately it consumes cpu cycles. but its not happening. where am i understanding wrong.
    If you are referring to this:

    "timeout is an upper bound on the amount of time elapsed before select()
    returns. If both fields of the timeval structure are zero, then
    select() returns immediately. (This is useful for polling.) If time‐
    out is NULL (no timeout), select() can block indefinitely."

    The timeval structure having fields of 0 is not the save thing as using 0 for the timeout in the select call. When you put 0 in the select call, that is the NULL case, (no timeout) which would block indefinitely.

  5. #5
    Join Date
    Jul 2013
    Posts
    6
    Qt products
    Qt/Embedded
    Platforms
    Unix/X11

    Default Re: External and Internal Event Processing in Qt

    in the souece code deliberately timeval struct is filled with zeros. i.e pointer iss not null and waiting time is zero so that select immediately returns. it doesnt block. moreover if it blocks on fds timers timeout will not be honoured.

  6. #6
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: External and Internal Event Processing in Qt

    Luckily, when you have timers, then the wait values are not zero.

    Cheers,
    _

  7. #7
    Join Date
    Jul 2013
    Posts
    6
    Qt products
    Qt/Embedded
    Platforms
    Unix/X11

    Default Re: External and Internal Event Processing in Qt

    if no timers are there in code, select call will be repeated in a while loop with timeval struct filled with zeros.
    when i did the same in a sample linux program, it has taken 100% cpu utilization. but Qt applications are not taking so. thats where i stumbled to understand how much value is filled in timeval struct and where in the code???
    VIJAYAKUMAR.VEDAVALLI

  8. #8
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: External and Internal Event Processing in Qt

    Quote Originally Posted by vijay523201 View Post
    if no timers are there in code, select call will be repeated in a while loop with timeval struct filled with zeros.
    Only if also the condition "canWait" is false. If it is true, select is called with a null pointer.

    Quote Originally Posted by vijay523201 View Post
    i
    when i did the same in a sample linux program, it has taken 100% cpu utilization. but Qt applications are not taking so.
    That's because the Qt event loop is not doing that.

    Quote Originally Posted by vijay523201 View Post
    thats where i stumbled to understand how much value is filled in timeval struct and where in the code???
    Most code is on QEventDispatcherUNIX:rocessEvents().
    If there are timers and timers are not excluded by processing flags, then the timeout is calculated in QTimeInfoList::timerWait()

    Cheers,
    _

  9. #9
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: External and Internal Event Processing in Qt

    Quote Originally Posted by vijay523201 View Post
    nowhere in code it is filled to non zero value.
    Of course it is, e.g. in QEventDispatcherUNIX.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


Similar Threads

  1. Replies: 4
    Last Post: 15th July 2012, 03:41
  2. moc.exe is not recognized as an internal or external command
    By Deshi in forum Installation and Deployment
    Replies: 4
    Last Post: 23rd January 2010, 01:40
  3. Event Processing
    By QbelcorT in forum Qt for Embedded and Mobile
    Replies: 10
    Last Post: 16th April 2009, 00:48
  4. Replies: 15
    Last Post: 17th June 2007, 18:41
  5. 'make' is not recognized as an internal or external command
    By jivanr in forum Installation and Deployment
    Replies: 1
    Last Post: 9th June 2007, 16:55

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.