PDA

View Full Version : How to save file with QFileDialog



pnikolov
2nd July 2008, 21: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, 22: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, 11: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, 15:43
*lol*

:eek: sorry, could not resist

jacek
3rd July 2008, 20: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.

chochatown
19th June 2009, 17:36
Hello
i try to use Qfiledialog for a save dialog too
but ther is an error that i cant see the reason that's my code

<code>
void Frm::evtBtnFileTarget()
{
QFileDialog::getSaveFileName(this, "Save file", "", ".conf");
}
</code>

that's the error:

Frm.cpp:945: erreur: no matching function for call to «QFileDialog::getSaveFileName(Frm* const, const char [10], const char [1], const char [6])»
/usr/include/qt4/QtGui/qfiledialog.h:201: note: candidats sont: static QString QFileDialog::getSaveFileName(QWidget*, const QString&, const QString&, const QString&, QString*, QFlags<QFileDialog::Option>)



thx

Lykurg
19th June 2009, 17:38
your class Frm must be a subclass of QWidget or pass 0 instead of this as the first parameter

chochatown
20th June 2009, 00:26
c'est bien ca, Mercii;)

prabhudev
23rd May 2012, 07:32
QString s = QFileDialog::getSaveFileName(
"/home",
"Images (*.png *.xpm *.jpg)",
this,
"save file dialog",
"Choose a filename to save under" );

use this works fine
http://linux.die.net/man/3/qfiledialog

d_stranz
28th May 2012, 04:00
Thanks for the timely response. I'm sure these guys have been struggling to find this answer since 2009.

ChrisW67
28th May 2012, 04:22
Been a few of these lately. I suspect there will be another spate in three years ;)

prabhudev
1st June 2012, 10:23
The reason i answered because if in future if some1 have a same problem, he will have a solution here.