Results 1 to 8 of 8

Thread: QDoubleSpinBox setValue() performance issue

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,368
    Thanks
    3
    Thanked 5,018 Times in 4,794 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QDoubleSpinBox setValue() performance issue

    Correct me if I'm wrong but if you change values to those spinboxes every 20ms, they need to be redrawn 50 times per second. 50 * 20 = 1000. That's how many times per second the paintEvent of the spinbox class is called.

    I suggest you do something like this:
    Qt Code:
    1. QVector<qreal> values(20, 0.0);
    2. QTimer *updateTimer = new QTimer(this);
    3. connect(updateTimer, SIGNAL(timeout()), this, SLOT(updateBoxes()));
    4. updateTimer->start(500); // 2Hz
    5. //...
    6. void XX::updateBoxes(){
    7. for(int i=0;i<20;i++){
    8. qreal val = values[i];
    9. QDoubleSpinBox *sb = boxes[i];
    10. sb->setValue(val);
    11. }
    12. }
    To copy to clipboard, switch view to plain text mode 

    That's more or less what you did in your first approach. Just make sure the "transferAxesToSpinboxes()" method is called 1-2 times a second at most. You won't notice more values of 20 boxes per second anyway.

  2. The following user says thank you to wysota for this useful post:

    Cruz (17th February 2009)

Similar Threads

  1. Performance Issue
    By linuxdev in forum Qt Programming
    Replies: 1
    Last Post: 10th December 2008, 15:00

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
  •  
Qt is a trademark of The Qt Company.