PDA

View Full Version : QFileDialog freezes



FreddyKay
20th November 2014, 14:18
Hey guys!

I got the fllowing problem, which is new for me. I want the user to enter a file location and file name, that I can use to create a file obviously. I got the following code for this:



void SpacecraftDataView::saveToFile(){

QString fileName = QFileDialog::getSaveFileName(this, "Save Data", "", "Textdatei (*.txt);;All Files(*)");

if(fileName.isEmpty()){
return;
}else{
QTextDocumentWriter writer(fileName);
if(!writer.write(&dataProcessor->getDocument())){
QMessageBox::information(this, tr("Unable to write to file"), "Writing to file was not possible.");
return;
}else{
//! \todo something here
}
}

}


Note it does not execute past the getSaveFileName part. This does open a QFileDialog which then freezes in the middle of its execution, see screenshot:

http://imagizer.imageshack.us/a/img661/1187/bK1j4n.jpg

So what am I doing wrong?

StrikeByte
21st November 2014, 10:33
have you tried to set a start folder for the dialog?

d_stranz
22nd November 2014, 01:37
Try putting "*.*" in your "All Files" filter. It's possible that's what is causing the hangup. If you don't specify a starting directory, it will default to the app's current directory.

FreddyKay
24th November 2014, 14:46
I tried both and it was both not helping.

What did solve the problem was setting the option
QFileDialog::DontUseNativeDialog.

So I suppose there is something interfering with Qts Native Dialog. I suspect it is some kind of Plugin, though I dont know a way how to find that plugin. Any Ideas?

ChrisW67
24th November 2014, 20:14
The native dialog is not part of Qt but part of your operating system/window manager. Once Qt opens that dialog what it does as it initialises is not within Qt control.