ToddAtWSU
11th March 2013, 12:51
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.
void MainWindow::openFiles( )
{
QStringList filenames = QFileDialog::getOpenFileNames( ... )
int numFiles = filenames.size( );
QProgressDialog progress( "Opening Files...", "Cancel", 0, numFiles, this );
progress.setWindowModality( Qt::WindowModal );
progress.setMinimumDuration( 0 );
progress.setValue( 0 );
progress.raise( ); // I have also tried progress.show( )
foreach( QString filename, filenames )
{
progress.setLabelText( QString( "Opening file %1 of %2 ).arg( progress.value( ) + 1 ).arg( numFiles ) );
openFile( filename ); // Code that does the reading in and storing of the file
if( progress.wasCanceled( ) )
{
break;
}
progress.setValue( progress.value( ) + 1 );
}
progress.setValue( progress.maximum( ) );
}
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
void MainWindow::openFiles( )
{
QStringList filenames = QFileDialog::getOpenFileNames( ... )
int numFiles = filenames.size( );
QProgressDialog progress( "Opening Files...", "Cancel", 0, numFiles, this );
progress.setWindowModality( Qt::WindowModal );
progress.setMinimumDuration( 0 );
progress.setValue( 0 );
progress.raise( ); // I have also tried progress.show( )
foreach( QString filename, filenames )
{
progress.setLabelText( QString( "Opening file %1 of %2 ).arg( progress.value( ) + 1 ).arg( numFiles ) );
openFile( filename ); // Code that does the reading in and storing of the file
if( progress.wasCanceled( ) )
{
break;
}
progress.setValue( progress.value( ) + 1 );
}
progress.setValue( progress.maximum( ) );
}
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