PDA

View Full Version : How to save file with QFileDialog


pnikolov
2nd July 2008, 22:37
Hello,
I read the QFileDialog class reference, but I still cannot solve the following problem:
I want to impelement a posibility for the user to save a file. I use Python and PyQt4, but if you have a C++ solution please wirte it...
I use:
QtGui.QFileDialog.getSaveFileName(self, "Save file", "", ".conf")

But when I press the Save button from the showed Dialog, there is no saved file..
I tried using:

filename = QtGui.QFileDialog.getSaveFileName(self, "Save file", "", ".conf")

where filename is previosly opened file or string... but no success
I read somewhere that getSavedFileName() returns the selected filename even if there is no such file (?!?!)

I need your help.
All the best!

jacek
2nd July 2008, 23:16
QFileDialog only asks user for the file name. It won't save your data, because it doesn't even know what data to save.

In C++ you would do this:
filename = QFileDialog::getSaveFileName( ... );
QFile f( filename );
f.open( QIODevice::WriteOnly );
// store data in f
f.close();

pnikolov
3rd July 2008, 12:26
Thanks for the information.

And why the hell the method is called getSaveFileName() ??? :confused: And the displayed dialog contents the SAVE button? Is this a joke?

I suggested that:
filename = QtGui.QFileDialog.getSaveFileName(self, "Save file", "", ".conf")
will save the content of filename with the .conf extention... but no! I will do it manualy as you suggested... thanks!

ChristianEhrlicher
3rd July 2008, 16:43
*lol*

:eek: sorry, could not resist

jacek
3rd July 2008, 21:39
And why the hell the method is called getSaveFileName() ???
Because it returns the name of a file chosen by the user in which data should be saved. It can't do anything with the data, especially that you don't pass it as an argument.