PDA

View Full Version : SelectFile() is returning NULL



abhilashajha
9th June 2009, 13:44
Hello,
I want to retrieve selected file name from file dialog. I am using selectfile() function for this but it is not returning the value.
Below is the code snippet please let me know what is the problem.


SavePage()
{
QFileDialog dialog(this);
dialog.setMinimumSize(240, 320);
dialog.setAcceptMode (QFileDialog::AcceptSave);
dialog.resize(240,320);
dialog.setConfirmOverwrite(false);

QString fileName;

if (dialog.exec())
dialog.selectFile (fileName);
else
return;

// Open a file and Save in it
QFile file(fileName);
file.open(QIODevice::WriteOnly);
QTextStream ts( &file);

}

spirit
9th June 2009, 13:50
according to you code fileName is an empty string, line 9.
QFileDialog::selectFile takes a const reference, so it should not modify fileName.

abhilashajha
9th June 2009, 14:09
Which function should I used to retrieve file name of the selected file?

spirit
9th June 2009, 14:11
QFileDialog::selectedFiles.

Lykurg
9th June 2009, 15:37
...or use the static QFileDialog::getSaveFileName() and check if empty.

abhilashajha
10th June 2009, 06:10
I tried using this getSavefileName() static method but I was not able to resize it's window size. I am developing application for mobile device hence I want to resize the dialog window as per my device resolution.

abhilashajha
10th June 2009, 12:30
Thanks!! Problem is solved.