Results 1 to 7 of 7

Thread: Using QProgressBar

  1. #1
    Join Date
    Oct 2009
    Posts
    28
    Thanks
    4
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Using QProgressBar

    Hello everyone.

    I'm developing an app that requires the control of the main thread (GUI thread) for a while (few seconds). Despite this time is not so longer, I would like to show an QProgressBar in the middle of the screen to show to the user that an operations is being executed and he must wait.

    I tried to do it with a QThread, but I was not possible because You can't create gui objects ( a Qwidget with the QProgressBar inside) outside the Gui Thread.

    Thanks a lot in advance.

  2. #2
    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: Using QProgressBar

    Where does you app get busy for the few seconds ??
    You can call qApp->processEvents() from that loop...

    OR

    you can make a custom widget to show the progress.. show the widget before starting your operation and close it after the operation. You need not be accurate for the operation to complete. You simply need to show to the user that the application is busy

  3. The following user says thank you to aamer4yu for this useful post:

    gutiory (30th April 2010)

  4. #3
    Join Date
    Jan 2008
    Location
    Poland
    Posts
    687
    Thanks
    4
    Thanked 140 Times in 132 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Using QProgressBar

    You have to do it in the opposite way - perform your long operation in QThread (take only this part which not requires any GUI) and show your progress bar in main thread.
    I would like to be a "Guru"

    Useful hints (try them before asking):
    1. Use Qt Assistant
    2. Search the forum

    If you haven't found solution yet then create new topic with smart question.

  5. The following user says thank you to faldzip for this useful post:

    gutiory (30th April 2010)

  6. #4
    Join Date
    Oct 2009
    Posts
    28
    Thanks
    4
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Using QProgressBar

    Thanks everyone for your quick answers.

    Quote Originally Posted by aamer4yu View Post
    Where does you app get busy for the few seconds ??
    You can call qApp->processEvents() from that loop...

    OR

    you can make a custom widget to show the progress.. show the widget before starting your operation and close it after the operation. You need not be accurate for the operation to complete. You simply need to show to the user that the application is busy
    Now I'm going to try to create the custom widget. I'll answer again later with the results.



    Quote Originally Posted by faldżip View Post
    You have to do it in the opposite way - perform your long operation in QThread (take only this part which not requires any GUI) and show your progress bar in main thread.
    I can't do what you've said, because the long operation comes from a GUI operation. I've a QTableView and I asign it a model that contains one hundred columns and fifteen rows. The asignment of the model to the view makes the app slow.

    Thanks again.
    Regards.

  7. #5
    Join Date
    Jan 2006
    Location
    Belgium
    Posts
    1,938
    Thanked 268 Times in 268 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Wiki edits
    20

    Default Re: Using QProgressBar

    Quote Originally Posted by gutiory View Post
    I can't do what you've said, because the long operation comes from a GUI operation. I've a QTableView and I asign it a model that contains one hundred columns and fifteen rows. The asignment of the model to the view makes the app slow.
    GUI operations can never take long! If they do, you're making a mistake, and the most common mistake with big lists is that all the items get drawn, even if they are not on screen. Thus: only draw those items that are on the screen. If you need to process the data, and it is a lot of data, then make sure you seperate the user interface and the data. Process the data in a seperate thread.

    Even if your list is small, seperate the processing from the viewing. If you need to read data from a file or a socket, make sure it is at least done asynchronous or in a seperate thread. You can even add a signal or function to that thread to report progress so you can add a progressdialog or progressbar and link it to that signal or function.

    Populate your model via a thread. You do not need to process your data inside the model, the model is just a container for your data, nothing more.

  8. #6
    Join Date
    Jan 2008
    Location
    Poland
    Posts
    687
    Thanks
    4
    Thanked 140 Times in 132 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Using QProgressBar

    Quote Originally Posted by gutiory View Post
    I can't do what you've said, because the long operation comes from a GUI operation. I've a QTableView and I asign it a model that contains one hundred columns and fifteen rows. The asignment of the model to the view makes the app slow.
    okay, so it means your model is containing a lot of data, so I would suggest you making your own model which would do some lazy/delayed data loading:
    1. You set your model to a view when it is still empty, so as fast as light :]
    2. Now fire some method in model - let's call it load() - to load the data, lets say row by row, the loading is done in separate thread.
    3. Your view can be updated on each row added (rowsInserted() and something like this).
    4. The progress bar can be displayed until loading is finished.

    This probably will take longer then just setting model like you have done it now, but will not freeze your GUI.
    I would like to be a "Guru"

    Useful hints (try them before asking):
    1. Use Qt Assistant
    2. Search the forum

    If you haven't found solution yet then create new topic with smart question.

  9. #7
    Join Date
    Oct 2009
    Posts
    28
    Thanks
    4
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Using QProgressBar

    Problem solved guys.
    Thanks a lot for your answer. You were completly right. The solution is creating a method that partially load data. The behavior of the app is the same I thought, but every content appears inmediatly.
    I've learnt so many things because of this problem.

    Thanks a lot again and sorry for answering so late.

    Regards.

Similar Threads

  1. update the QProgressBar
    By aloha in forum Newbie
    Replies: 16
    Last Post: 23rd April 2009, 20:07
  2. Use of QProgressBar in Thread
    By merry in forum Qt Programming
    Replies: 2
    Last Post: 5th January 2009, 21:53
  3. QProgressBar in QTreeWidget?
    By lvi in forum Qt Programming
    Replies: 5
    Last Post: 3rd September 2008, 19:48
  4. QProgressBar + Mac OS X
    By THRESHE in forum Qt Programming
    Replies: 5
    Last Post: 14th December 2007, 13:41
  5. QProgressBar & 200%
    By Dmitry in forum Qt Programming
    Replies: 2
    Last Post: 20th January 2006, 11:33

Tags for this Thread

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.