Results 1 to 12 of 12

Thread: How to save file with QFileDialog

  1. #1
    Join Date
    Jun 2008
    Location
    Bulgaria
    Posts
    5
    Qt products
    Qt4
    Platforms
    Windows

    Question How to save file with QFileDialog

    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:
    Qt Code:
    1. QtGui.QFileDialog.getSaveFileName(self, "Save file", "", ".conf")
    To copy to clipboard, switch view to plain text mode 

    But when I press the Save button from the showed Dialog, there is no saved file..
    I tried using:
    Qt Code:
    1. filename = QtGui.QFileDialog.getSaveFileName(self, "Save file", "", ".conf")
    To copy to clipboard, switch view to plain text mode 
    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!
    Last edited by pnikolov; 2nd July 2008 at 22:38. Reason: spelling error

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 975 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: How to save file with QFileDialog

    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:
    Qt Code:
    1. filename = QFileDialog::getSaveFileName( ... );
    2. QFile f( filename );
    3. f.open( QIODevice::WriteOnly );
    4. // store data in f
    5. f.close();
    To copy to clipboard, switch view to plain text mode 

  3. The following user says thank you to jacek for this useful post:

    spagatoni (1st December 2008)

  4. #3
    Join Date
    Jun 2008
    Location
    Bulgaria
    Posts
    5
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: How to save file with QFileDialog

    Thanks for the information.

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

    I suggested that:
    Qt Code:
    1. filename = QtGui.QFileDialog.getSaveFileName(self, "Save file", "", ".conf")
    To copy to clipboard, switch view to plain text mode 
    will save the content of filename with the .conf extention... but no! I will do it manualy as you suggested... thanks!

  5. #4
    Join Date
    Jan 2006
    Location
    Bremen, Germany
    Posts
    502
    Thanked 75 Times in 71 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Talking Re: How to save file with QFileDialog

    *lol*

    sorry, could not resist

  6. #5
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 975 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: How to save file with QFileDialog

    Quote Originally Posted by pnikolov View Post
    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.

  7. #6
    Join Date
    May 2009
    Posts
    15
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: How to save file with QFileDialog

    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

  8. #7
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: How to save file with QFileDialog

    your class Frm must be a subclass of QWidget or pass 0 instead of this as the first parameter

  9. #8
    Join Date
    May 2009
    Posts
    15
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: How to save file with QFileDialog

    c'est bien ca, Mercii

  10. #9
    Join Date
    May 2012
    Posts
    33
    Thanks
    9
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: How to save file with QFileDialog

    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

  11. #10
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    4,714
    Thanks
    259
    Thanked 759 Times in 749 Posts
    Qt products
    Qt5
    Platforms
    Windows Android

    Default Re: How to save file with QFileDialog

    Thanks for the timely response. I'm sure these guys have been struggling to find this answer since 2009.

  12. #11
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,677
    Thanks
    13
    Thanked 1,596 Times in 1,524 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: How to save file with QFileDialog

    Been a few of these lately. I suspect there will be another spate in three years

  13. #12
    Join Date
    May 2012
    Posts
    33
    Thanks
    9
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: How to save file with QFileDialog

    The reason i answered because if in future if some1 have a same problem, he will have a solution here.

Similar Threads

  1. QFileDialog and file extension
    By calhal in forum Qt Programming
    Replies: 3
    Last Post: 9th March 2010, 13:54
  2. Set up the Qt4.3.2 with Visual Studio 2005
    By lamoda in forum Installation and Deployment
    Replies: 6
    Last Post: 30th January 2008, 07:51
  3. QFileDialog and file sequences
    By peterhillman in forum Qt Programming
    Replies: 5
    Last Post: 24th November 2007, 11:16
  4. Replies: 4
    Last Post: 13th June 2007, 16:37
  5. qt-3.3.8 fail in scratchbox
    By nass in forum Installation and Deployment
    Replies: 0
    Last Post: 25th May 2007, 16:21

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.