Falling down if you press the "close button"

QFileDialog dlg(this); QString D_path = "C:/WORK/"; QString D_format = "bin"; QString isRead; isRead = dlg.getOpenFileName(this,trUtf8("Открываем данные зарегистрированные осциллографом"),D_path,trUtf8("DUMP(*.%1)").arg(D_format)); 

    2 answers 2

    I will give an example of use and design:

     const QString & fileName = QFileDialog::getOpenFileName( this ); if ( fileName.isEmpty() ) return; QFile file( fileName ); if ( !file.open( QIODevice::ReadOnly ) ) return; QTextStream out( &file ); out.setCodec( "utf8" ); setText( out.readAll() ); 

    It is used in the function (as hinted at by return ), otherwise we change the test and work with if'ami to the opposite:

     const QString & fileName = QFileDialog::getOpenFileName( this ); if ( !fileName.isEmpty() ) { QFile file( fileName ); if ( file.open( QIODevice::ReadOnly ) ) { QTextStream out( &file ); out.setCodec( "utf8" ); setText( out.readAll() ); } } 

      You just need to add a check for file fullness.

        isRead = dlg.getOpenFileName(this,trUtf8("Открываем данные зарегистрированные осциллографом"),D_path,trUtf8("DUMP(*.%1)").arg(D_format)); if(isRead.isEmpty()) { return; } 

      I understand that the question is trivial but he got me. Here is the official answer to my question. Warning: Do not delete the parent. If you want to do this, you should create a QFileDialog constructors.