Results 1 to 3 of 3

Thread: QProgressDialog Not Showing

  1. #1
    Join Date
    Jan 2006
    Location
    Ohio
    Posts
    332
    Thanks
    37
    Thanked 8 Times in 4 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Question QProgressDialog Not Showing

    I have a function that allows the user to open multiple files. These files are basic ASCII text files but can be multiple megabytes long containing a lot of information that unfortunately takes a little time to load. Depending on the number of files they open, it can take upwards of a minute. I want to assure the user the program hasn't hung by using a QProgressDialog to show them stuff is happening. However, the QProgessDialog never shows until the final couple seconds and is fairly useless. I thought it was the 4-second delay the dialog has, but it will take longer than 4 seconds for it to show and I have tried changing the minimum duration but it still doesn't work. Here is my code, can you please tell me where I am making a mistake. Sorry for any typos in my code, it resides on a standalone network so I am typing this back in by hand from a printout.

    Qt Code:
    1. void MainWindow::openFiles( )
    2. {
    3. QStringList filenames = QFileDialog::getOpenFileNames( ... )
    4. int numFiles = filenames.size( );
    5. QProgressDialog progress( "Opening Files...", "Cancel", 0, numFiles, this );
    6. progress.setWindowModality( Qt::WindowModal );
    7. progress.setMinimumDuration( 0 );
    8. progress.setValue( 0 );
    9. progress.raise( ); // I have also tried progress.show( )
    10.  
    11. foreach( QString filename, filenames )
    12. {
    13. progress.setLabelText( QString( "Opening file %1 of %2 ).arg( progress.value( ) + 1 ).arg( numFiles ) );
    14. openFile( filename ); // Code that does the reading in and storing of the file
    15.  
    16. if( progress.wasCanceled( ) )
    17. {
    18. break;
    19. }
    20.  
    21. progress.setValue( progress.value( ) + 1 );
    22. }
    23.  
    24. progress.setValue( progress.maximum( ) );
    25. }
    To copy to clipboard, switch view to plain text mode 

    Thanks for your help. I am running this on Qt 4.7.3 on Solaris 10. Of note, the input window from QFileDialog::getOpenFileNames shows me the gray outline from this dialog...so it's not redrawing the QMainWindow right away when the user closes the dialog. I don't know if this is causing some of the issues which is why I tried calling raise( ) on the QProgressDialog.

    Thanks again!
    Todd

  2. #2
    Join Date
    Mar 2008
    Location
    Kraków, Poland
    Posts
    1,536
    Thanked 284 Times in 279 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QProgressDialog Not Showing

    The problem well-known and described under the heading "qt gui responsive". Ask Mr Google.

  3. #3
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: QProgressDialog Not Showing

    You are not allowing the main thread to do any event processing because you stay in a tight loop and do not return to the event loop.
    Thus it cannot do any process any updates, neither for your main UI nor for the progress dialog.

    If loading of a single file is fast enough you can call QCoreApplication:rocessEvents() in between files, ideally later on refactoring it to process files from a queue with a slot that is called through delayed invocation for every run.

    If loading of a single file can take longer than a user would be comfortable with, then you'll either need to do event process in the loading code or move loading to a thread.

    Cheers,
    _

Similar Threads

  1. QTreeWidget and QProgressDialog?
    By progman in forum Newbie
    Replies: 6
    Last Post: 18th March 2010, 18:05
  2. Need help in QProgressDialog
    By santhoshv84 in forum Qt Programming
    Replies: 3
    Last Post: 12th September 2008, 18:24
  3. QProgressDialog
    By samirg in forum Qt Programming
    Replies: 5
    Last Post: 5th September 2007, 16:37
  4. Showing QMainWindow without showing a child QWidget
    By discostu in forum Qt Programming
    Replies: 3
    Last Post: 4th March 2007, 09:03
  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.