Results 1 to 5 of 5

Thread: QProgress Bar-Time Measuring

  1. #1
    Join Date
    Feb 2007
    Posts
    42
    Thanks
    3
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Question QProgress Bar-Time Measuring

    hi,

    how can i make a progress bar count time?
    I have an operation that needs 2.5 minutes to complete and i want a progress bar to count this time....

    any ideas??

    N.A

  2. #2
    Join Date
    Feb 2006
    Location
    Romania
    Posts
    2,744
    Thanks
    8
    Thanked 541 Times in 521 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QProgress Bar-Time Measuring

    What if you run it on another computer and it will take 3 minutes or 1 minute?
    QProgressBar is used to display the completed amount of a certain process.

    Anyway, if you really want to do this, us a QTimer and update the progress bar every 10 secs or so. You will know that 2.5 minutes have passed by computing the time difference between when the QTimer started and the QTimer stopped.
    Something like this:

    Qt Code:
    1. void Class::timeoutSlot()
    2. {
    3. int elapsed = mStartTime.secsTo( QTime::currentTime() );
    4. if( elapsed / 60.0f >= 2.5f )
    5. {
    6. //This means 2.5 mins have elapsed
    7. }
    8. else
    9. {
    10. mProgressBar->setValue( mProgressBar->value() + 10 );
    11. }
    12. }
    To copy to clipboard, switch view to plain text mode 

    Above mStartTime is a QTime::currentTime created when you start your progress created when, and your QTimer has a 10 seconds timeout with its timeout signal connected to timeoutSlot().

    Regards

  3. #3
    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: QProgress Bar-Time Measuring

    I suggest using QTimeLine. You can then easily choose the update period.

    Qt Code:
    1. QTimeLine *tl = new QTimeLine;
    2. tl->setDuration(150000);
    3. tl->setRange(0, 150); // update every second
    4. tl->setLoopCount(1);
    5. pb->setRange(0, 150); // the same as for the time line
    6. connect(tl, SIGNAL(frameChanged(int)), pb, SLOT(setValue(int)));
    7. pb->setValue(0);
    8. connect(tl, SIGNAL(finished()), tl, SLOT(deleteLater())); // cleanup
    9. tl->start();
    To copy to clipboard, switch view to plain text mode 

  4. #4
    Join Date
    Feb 2006
    Location
    Romania
    Posts
    2,744
    Thanks
    8
    Thanked 541 Times in 521 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QProgress Bar-Time Measuring

    Yes, better...

  5. #5
    Join Date
    Feb 2007
    Posts
    42
    Thanks
    3
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QProgress Bar-Time Measuring

    thanks for the answer, the operation virtually lasts for 2,5 minutes {it emulates time} so that's why i wanted it!

Similar Threads

  1. time and date issues
    By boog07005 in forum Newbie
    Replies: 5
    Last Post: 20th August 2012, 15:15
  2. GUI Thread getting no time to process
    By steg90 in forum Qt Programming
    Replies: 11
    Last Post: 9th May 2007, 09:29
  3. Displaying real time images
    By Sheetal in forum Qt Programming
    Replies: 9
    Last Post: 22nd February 2007, 11:29
  4. QDateTime GMT add sec. or - sec. from locale time....
    By patrik08 in forum Qt Programming
    Replies: 2
    Last Post: 20th February 2007, 16:39
  5. Problem with pointers while using localtime() and time()
    By jamadagni in forum General Programming
    Replies: 7
    Last Post: 11th January 2006, 15:48

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.