Results 1 to 10 of 10

Thread: QProgressDialog is slowing down loop?

  1. #1
    Join Date
    Jun 2011
    Posts
    4
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default QProgressDialog is slowing down loop?

    I have simple loop looking for expression in QStringList.
    Whenever I add
    progressDialog2.setLabelText(tr("Searching %1 of %2...").arg(i).arg(fields_size));

    it slows down as hell
    Qt Code:
    1. for (int i = 0; i < fields_size; ++i) {
    2. progressDialog2.setValue(i);
    3. progressDialog2.setLabelText(tr("Searching %1 of %2...").arg(i).arg(fields_size));
    4. qApp->processEvents();
    5.  
    6. if (progressDialog2.wasCanceled()){
    7. fields_step.append("Canceled");
    8. fileName = fileName + "_Canceled";
    9. break;
    10. } else if (fields.at(i).contains(rx1)) {
    11. fields_step.append(fields.at(i));
    12. }
    13. }
    To copy to clipboard, switch view to plain text mode 
    What I am doing wrong?

  2. #2
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: QProgressDialog is slowing down loop?

    You are setting the position of the progress bar (unavoidable) and triggering a translation lookup and two int to string conversions every time through the loop. Do you really need to repeat the progress figure in the label? If not, then the label should be set once outside the loop.

  3. #3
    Join Date
    Jun 2011
    Posts
    4
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QProgressDialog is slowing down loop?

    If I comment out setLabelText it is just 20 times slower rather without progresbarr at all.
    no progress bar = ~0.5s
    progres bar no label = ~5s
    bar and label = ~20s

    maybe putting these in thread or something will help?

  4. #4
    Join Date
    Jun 2011
    Location
    Finland
    Posts
    164
    Thanks
    1
    Thanked 26 Times in 26 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Maemo/MeeGo

    Default Re: QProgressDialog is slowing down loop?

    Calling setValue on a progressBar on every iteration isn't good idea either if you have thousand iterations. Do it only if the step is bigger or equal 1% of the operation.
    Last edited by Rachol; 28th June 2011 at 11:48.

  5. #5
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: QProgressDialog is slowing down loop?

    Is there any point to a progress bar for a half-second process?

  6. #6
    Join Date
    Mar 2011
    Location
    Hyderabad, India
    Posts
    1,882
    Thanks
    3
    Thanked 452 Times in 435 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows
    Wiki edits
    15

    Default Re: QProgressDialog is slowing down loop?

    Using a thread will not decrease the time required to execute to loop, unless you have multi-core / multi processor system, even in this case the time will not reduce if you update the QProgrssBar every iteration.

    You can use the loop in another thread just to increase the GUI response, but still the loop will take its same time.

  7. #7
    Join Date
    Jun 2011
    Posts
    4
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QProgressDialog is slowing down loop?

    Quote Originally Posted by ChrisW67 View Post
    Is there any point to a progress bar for a half-second process?
    Is is 0.5 just in this example - test case.

    Quote Originally Posted by Rachol View Post
    Do it only if the step is bigger or equal 1% of the operation.
    So I recount my counter to 100% and then just if update label if step is more than 1%?

  8. #8
    Join Date
    Sep 2009
    Location
    Wroclaw, Poland
    Posts
    1,394
    Thanked 342 Times in 324 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: QProgressDialog is slowing down loop?

    What is the value of fields_size in this example ?

  9. #9
    Join Date
    Jun 2011
    Location
    Finland
    Posts
    164
    Thanks
    1
    Thanked 26 Times in 26 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Maemo/MeeGo

    Default Re: QProgressDialog is slowing down loop?

    Quote Originally Posted by marwooj View Post
    So I recount my counter to 100% and then just if update label if step is more than 1%?
    Yes, call setValue() and processEvents() only when the step is >= 1%

  10. #10
    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: QProgressDialog is slowing down loop?

    Updating a progress bar will always be slower than not updating it. Remember that processEvents() triggers all events and not just repaint of your progress dialog. Overall it is a time consuming process that would better be spent on doing the actual operation.
    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. Main loop thread loop communication
    By mcsahin in forum Qt Programming
    Replies: 7
    Last Post: 25th January 2011, 16:31
  2. QTreeWidget and QProgressDialog?
    By progman in forum Newbie
    Replies: 6
    Last Post: 18th March 2010, 18:05
  3. Need help in QProgressDialog
    By santhoshv84 in forum Qt Programming
    Replies: 3
    Last Post: 12th September 2008, 18:24
  4. QProgressDialog
    By samirg in forum Qt Programming
    Replies: 5
    Last Post: 5th September 2007, 16:37
  5. qprogressDialog
    By mickey in forum Qt Programming
    Replies: 5
    Last Post: 17th July 2006, 14:16

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.