Results 1 to 3 of 3

Thread: QFile Question

  1. #1
    Join Date
    Jun 2014
    Posts
    33
    Thanks
    15
    Qt products
    Qt4
    Platforms
    Unix/X11

    Question QFile Question

    Hi all,

    Now i have a method as following

    Qt Code:
    1. void Dialog::saveValue()
    2. {
    3. QString path="/home/pi/valueHSV/hsv.xml";
    4. QFile valueHSV(path);
    5. valueHSV.open(QIODevice::WriteOnly);
    6. ...
    7. }
    To copy to clipboard, switch view to plain text mode 

    I would like to change the "path" in different situation,

    I tried writing a switch case in different method and call to saveValue mathod, this won't work,
    I tried to do a switch case inside saveValue method, this won't work too.

    Please advise, Thanks

  2. #2
    Join Date
    Sep 2009
    Location
    Wroclaw, Poland
    Posts
    1,394
    Thanked 342 Times in 324 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: QFile Question

    I'm not sure what you want to achieve. You can always create a "saveFile" function taking a QString as parameter and call it with different arguments:
    Qt Code:
    1. void Dialog::saveFile(const QString& path)
    2. {
    3. QFile valueHSV(path);
    4. valueHSV.open(QIODevice::WriteOnly);
    5. ...
    6. }
    7.  
    8. //
    9. void Dialog::saveValue()
    10. {
    11. QString path="/home/pi/valueHSV/hsv.xml";
    12. this->saveFile(path);
    13. QString differentPath="/home/pi/valueHSV/another.xml";
    14. this->saveFile(differentPath);
    15. ...
    16. }
    To copy to clipboard, switch view to plain text mode 
    If you want to manually select the save file path, you can use QFileDialog:
    Qt Code:
    1. void Dialog::saveValue()
    2. {
    3. QString path=QFileDialog::getSaveFileName(this, tr("Save File"),
    4. "/home/my_path/",
    5. tr("Xml Files(*.xml)");
    6. if (!path.isEmpty()){
    7. QFile valueHSV(path);
    8. valueHSV.open(QIODevice::WriteOnly);
    9. ...
    10. }
    11. }
    To copy to clipboard, switch view to plain text mode 

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

    YDYD (10th July 2014)

  4. #3
    Join Date
    Jun 2014
    Posts
    33
    Thanks
    15
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: QFile Question

    WOW!! Stampede!

    You really help me a lot!!

    Thanks again!!! =)

Similar Threads

  1. Replies: 2
    Last Post: 6th May 2013, 09:06
  2. Question about using QFile and QTextStream
    By liuliuwang in forum Newbie
    Replies: 3
    Last Post: 14th October 2010, 00:33
  3. Qfile Question - hard coded path
    By fortyhideout12 in forum Qt Programming
    Replies: 3
    Last Post: 27th September 2010, 21:50
  4. QFile open question
    By chenxuelian in forum Qt Programming
    Replies: 9
    Last Post: 2nd April 2010, 11:00
  5. Qfile question
    By dreamer in forum Qt Programming
    Replies: 1
    Last Post: 3rd May 2008, 16:32

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.