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() ); } }