Results 1 to 16 of 16

Thread: Adding a Progress bar

  1. #1
    Join Date
    Feb 2009
    Posts
    143
    Thanks
    8

    Post Adding a Progress bar

    Hi

    I have built a app that needs about 25 seconds to complete the execution(it needs to read from a device)

    When its executing, my app window just goes white.

    I want to add a progress bar to indicate how many seconds are left before it completes executing.

    I have added the progess bar in the ui design, but i have no idea as tohow to call it in my function and display % left befor completion.

    i have used this only.

    ui->progressBar->reset();
    ui->progressBar->setRange(0,100);
    ui->progressBar->setValue(50);

    I have added the last command, in the function that needs 25 seconds, but as the app freezes, the increment is not shown.


    I have seen the documentation, but it doesnt actually help me as to how my progress bar should look like. i am new to Qt, so i am hoping someone can help.

    I need a progress bar, that keeps increasing from 0% to 5% to 10% and so on till 100 is reached and in 25 seconds. A constant moving bar.

    When the control goes inside the function, all the ui commands in there arent shown in realtime. i.e. the execution is not shown as the app has only a white screen.

    can anybody help?

    thanks
    Last edited by srohit24; 27th May 2009 at 08:29.

  2. #2
    Join Date
    Feb 2008
    Posts
    157
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Adding a Progress bar

    call update() on the widget (in your case the progressbar) to make sure your changes are updated directly.

  3. #3
    Join Date
    Oct 2006
    Location
    New Delhi, India
    Posts
    2,467
    Thanks
    8
    Thanked 334 Times in 317 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Adding a Progress bar

    Either use threads for the heavy computing..
    or call qApp->processEvents() from your heavy computation loop...

  4. #4
    Join Date
    Sep 2008
    Location
    Bangalore
    Posts
    659
    Thanks
    116
    Thanked 42 Times in 41 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Adding a Progress bar

    Quote Originally Posted by srohit24 View Post
    Hi

    I need a progress bar, that keeps increasing from 0% to 5% to 10% and so on till 100 is reached and in 25 seconds. A constant moving bar.
    i cant make QProgreeBar update in a regular fashion but htis code will be useful for u ..
    use timer ..
    Qt Code:
    1. timer = new QTimer();
    2. timer->start(5000);
    3. connect(timer, SIGNAL(timeout()), this, SLOT(updateProgressBar()));
    To copy to clipboard, switch view to plain text mode 
    in update updateProgressBar slot
    Qt Code:
    1. ::updateProgressBar(){
    2. int curVal = progressbar->value();
    3. if(curVal == 100){
    4. timer->stop();
    5. return ;
    6. }else
    7. progressbar->setValue(curVal + 25);
    8. }
    To copy to clipboard, switch view to plain text mode 
    When the control goes inside the function, all the ui commands in there arent shown in realtime. i.e. the execution is not shown as the app has only a white screen.

    can anybody help?

    thanks
    use separate event loop for that function .. it is blocking the user interface ..
    use QThread ..
    use this link
    http://doc.trolltech.com/qq/qq27-responsive-guis.html
    "Behind every great fortune lies a crime" - Balzac

  5. #5
    Join Date
    Feb 2009
    Posts
    143
    Thanks
    8

    Default Re: Adding a Progress bar

    thanks for replying guys.

    I went through your link, wagmare.

    I think that Waiting in a Local Event Loop or Parallel Programming method will work fine for me.

    but i am not sure as to how to use it.

    My programs flow is something like this

    I press a button, this in turn calls the function that reads the data from the device.

    the data is read from the device from 2 separate locations. 1st time its very quick.

    the 2nd once takes 25 seconds.

    after the reading is over, it performs some calculations and displays the result within 2 seconds.

    i dont know where to and how to modify this code

    Qt Code:
    1. QNetworkAccessManager manager;
    2. QTimer tT;
    3.  
    4. tT.setSingleShot(true);
    5. connect(&tT, SIGNAL(timeout()), &q, SLOT(quit()));
    6. connect(&manager, SIGNAL(finished(QNetworkReply*)),
    7. &q, SLOT(quit()));
    8. QNetworkReply *reply = manager.get(QNetworkRequest(
    9. QUrl("http://www.qtcentre.org")));
    10.  
    11. tT.start(5000); // 5s timeout
    12. q.exec();
    13.  
    14. if(tT.isActive()){
    15. // download complete
    16. tT.stop();
    17. } else {
    18. // timeout
    19. }
    To copy to clipboard, switch view to plain text mode 

    or

    Qt Code:
    1. QList<QImage> images = loadImages(directory);
    2. ThumbThread *thread = new ThumbThread;
    3. connect(thread, SIGNAL(finished(QList<QImage>)),
    4. this, SLOT(showThumbnails(QList<QImage>)));
    5. thread->start(images);
    To copy to clipboard, switch view to plain text mode 

    it would be great if you can help.
    Last edited by srohit24; 27th May 2009 at 18:02.

  6. #6
    Join Date
    Sep 2008
    Location
    Bangalore
    Posts
    659
    Thanks
    116
    Thanked 42 Times in 41 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Adding a Progress bar

    QThread is the much better one to use ..... because u need to wait for 25 sec ... so ur event loop will resist or block the user interface for 25 seconds freezing the GUI ..to update()
    best go for QThread ... a separate event loop ...

    this example does what u need exactly ....
    http://doc.trolltech.com/4.5/network...uneclient.html

    have a good day ....
    "Behind every great fortune lies a crime" - Balzac

  7. #7
    Join Date
    Feb 2009
    Posts
    143
    Thanks
    8

    Default Re: Adding a Progress bar

    thanks for the promt reply mate.

    but the whole program is way over my head.

    I have a huge application now, about 600 lines of code, to redo everything is a bit tough.

    Is there a simple function, using which i can get back the control for the GUI while the reading takes place in the background??

    can i use the sleep command in the the reading function to get a small amount of work done?

    thanks.

  8. #8
    Join Date
    Sep 2008
    Location
    Bangalore
    Posts
    659
    Thanks
    116
    Thanked 42 Times in 41 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Adding a Progress bar

    Quote Originally Posted by srohit24 View Post
    thanks for the promt reply mate.
    Is there a simple function, using which i can get back the control for the GUI while the reading takes place in the background??

    can i use the sleep command in the the reading function to get a small amount of work done?
    no sleep will do no good ... it still freeze the gui main event loop

    u can use qApp->processEvents()

    void QCoreApplication:rocessEvents ( QEventLoop::ProcessEventsFlags flags = QEventLoop::AllEvents ) [static]
    "Behind every great fortune lies a crime" - Balzac

  9. #9
    Join Date
    Oct 2006
    Location
    New Delhi, India
    Posts
    2,467
    Thanks
    8
    Thanked 334 Times in 317 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Adding a Progress bar

    Only if u had read Post #3 a little carefully

  10. #10
    Join Date
    Feb 2009
    Posts
    143
    Thanks
    8

    Default Re: Adding a Progress bar

    Quote Originally Posted by wagmare View Post
    no sleep will do no good ... it still freeze the gui main event loop

    u can use qApp->processEvents()

    void QCoreApplication:rocessEvents ( QEventLoop::ProcessEventsFlags flags = QEventLoop::AllEvents ) [static]
    should i place this code in the main.cpp file? or in the class file that i am using to get the work done?

    can you be more specific as to what i must do to get the freezing to go away?

    Should i place the 25 seconds execution function in the above mentioned function?
    Last edited by srohit24; 29th May 2009 at 15:22.

  11. #11
    Join Date
    Feb 2009
    Posts
    143
    Thanks
    8

    Default Re: Adding a Progress bar

    can anyone guide me as to where i should place the processevents() function so that the GUI doesnt freeze?

  12. #12
    Join Date
    Oct 2006
    Location
    New Delhi, India
    Posts
    2,467
    Thanks
    8
    Thanked 334 Times in 317 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Angry Re: Adding a Progress bar

    Something like ..
    Qt Code:
    1. do
    2. {
    3. ...
    4. // Do you stuff
    5. qApp->processEvents(); // Call process events here..
    6. } while ( ! 25 seconds);
    To copy to clipboard, switch view to plain text mode 

  13. #13
    Join Date
    Feb 2009
    Posts
    143
    Thanks
    8

    Default Re: Adding a Progress bar

    ok. thanks

    i have build my app both in release and debug mode.

    when i double click on the exe in release folder, i get this error

    du.exe - Entry point not founf
    The procedure entry point ?? 0QCoreapplicaiton @@QAE@ABV0@@Z could not be located in the dynamic link library QtCore4.dll

    I have added #include <QCoreApplication> as a header in both main and the class file i have used.

    the exe in the debug folder works fine.

    how can i solve this?

  14. #14
    Join Date
    Jun 2007
    Location
    India
    Posts
    1,042
    Thanks
    8
    Thanked 133 Times in 128 Posts
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Adding a Progress bar

    you may be having more than one version of Qt dlls in your system...

    check your PATH variable.
    also check where is QtCore4d.dll(or QtCored4.dll i dont remember whats the name) ...

    make changes to your PATH and delete the old path to QtCore4.dll... and point it to the one where the debug dlls are located.. because there you will find the exact release dlls also

    or u can simply check your compiler/linker flags to see the paths

  15. The following user says thank you to nish for this useful post:

    srohit24 (1st June 2009)

  16. #15
    Join Date
    Feb 2008
    Posts
    157
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Adding a Progress bar

    As soon as you have one Qt application on your system which requires to be in the path, the dlls of your Qt Installation are likely not to be used. Therefor you must put all necessary dlls into your binary folder.

  17. #16
    Join Date
    Feb 2009
    Posts
    143
    Thanks
    8

    Default Re: Adding a Progress bar

    thanks it solved the problem.

Similar Threads

  1. QtItemDelegate for progress bars
    By maxpayne in forum Qt Programming
    Replies: 2
    Last Post: 19th November 2008, 13:26
  2. Concurrent progress reporting
    By chezifresh in forum Qt Programming
    Replies: 1
    Last Post: 30th June 2008, 08:47
  3. Adding JavaScript Obj to QWebView issues
    By bpetty in forum Newbie
    Replies: 2
    Last Post: 13th May 2008, 20:44
  4. Replies: 4
    Last Post: 11th March 2008, 11:44
  5. Adding buttons on the tab part of a tabwidget
    By forrestfsu in forum Qt Programming
    Replies: 2
    Last Post: 20th December 2006, 17:52

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.