void MainWindow::save()
{
const int currentIndex = tabWidget->currentIndex();
if( currentIndex == -1 )
return;
QString filepath = m_fileList.at( currentIndex )->filepath();
if( filepath.isEmpty() )
{
QString filters = tr("All files(*.*);;Textfiles(*.txt)");
filepath = QFileDialog::getOpenFileName( this, tr("Save file"), QDir::homePath() );
if( filepath.isEmpty() )
return;
}
QFile file( filepath );
if( !file.open( QIODevice::WriteOnly | QIODevice::Text ) )
return;
QTextStream str( &file );
str << m_fileList.at( currentIndex )->textEdit()->toPlainText();
file.close();
}
This code above works when debugging, only! If I run it, it crashes. But when I use the debugger and go through each step it doesn't. When I start the program through terminal and let it crash, it says Segmentation fault. I commented a lot of things out and ran it, to see where exactly it crashes. Apparently, when I call the QFileDialog, it crashes. It never shows but in debugging mode.
What's wrong? I'm on a linux machine (Ubuntu)