Results 1 to 2 of 2

Thread: CPU consumption

  1. #1
    Join Date
    Mar 2010
    Location
    spain
    Posts
    25
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default CPU consumption

    Curious phenomenon in CPU consumption.
    In the first code
    CPU consumption is zero

    Qt Code:
    1. Timer= new QTimer(this);
    2. connect(Timer, SIGNAL(timeout()), this, SLOT(Update())); // temporizaor horario
    3. Timer->start(10);
    To copy to clipboard, switch view to plain text mode 

    Qt Code:
    1. void StreamRender::Update(){
    2.  
    3.  
    4. QTimer::singleShot(30, this, SLOT(render()));
    5.  
    6. if (isFinal())
    7. {
    8. //if(Timer->isActive ())
    9. // {
    10. Timer->stop();
    11. emit Finish();
    12. // }
    13. }
    14.  
    15.  
    16.  
    17. }
    To copy to clipboard, switch view to plain text mode 

    second code
    CPU consumption of 10
    Qt Code:
    1. void StreamRender::Update(){
    2.  
    3.  
    4.  
    5. if (isFinal())
    6. {
    7. //if(Timer->isActive ())
    8. // {
    9. Timer->stop();
    10. emit Finish();
    11. // }
    12. }
    13.  
    14. render();
    15.  
    16. }
    To copy to clipboard, switch view to plain text mode 

    Any theories on this consumption.
    regards
    Last edited by valgaba; 1st April 2013 at 16:01.

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

    Default Re: CPU consumption

    Because in the first version of Update() that you posted, the single-shot timer does not fire until after the control returns to the event loop, so render() is never called in the Update() method. Also in that code, "Timer" refers to a different instance of QTimer; the call to QTimer::singleShot() creates a temporary QTimer instance that is destroyed once it times out and executes the render() slot.

    In the second version of Update(), render() is always called.

    Nothing curious about it. The two versions of your code are doing exactly what you've told them to do.

Similar Threads

  1. Memory Consumption (Qt with DirectX)
    By aaron1a12 in forum Qt Programming
    Replies: 1
    Last Post: 25th April 2012, 00:39
  2. QGraphicsScene - memory consumption
    By mateuszzz88 in forum Qt for Embedded and Mobile
    Replies: 3
    Last Post: 29th November 2010, 20:39
  3. QSqlQueryModel and memory consumption
    By lunatic fringe in forum Qt Programming
    Replies: 3
    Last Post: 5th February 2010, 11:09
  4. QTableView memory consumption
    By LordQt in forum Qt Programming
    Replies: 7
    Last Post: 9th December 2008, 16:51
  5. Pixmap memory consumption
    By bunjee in forum Qt Programming
    Replies: 9
    Last Post: 29th November 2007, 15:35

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.