Results 1 to 6 of 6

Thread: Settings for a particular file

  1. #1
    Join Date
    May 2010
    Posts
    8
    Qt products
    Qt4
    Platforms
    Windows

    Default Settings for a particular file

    Hi all,
    I need to store a setting related to the file in use; I know that with QSettings I can store the settings for my application, but in my case the setting is to be related to the file, so if I open file A I get the setting SA, if I open the file B I get the setting SB, etc... what is the best practice to do it in QT? Thank you in advance.

  2. #2
    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: Settings for a particular file

    Use QSettings and define the file:
    Qt Code:
    1. QSettings::QSettings ( const QString & fileName, Format format, QObject * parent = 0 );
    To copy to clipboard, switch view to plain text mode 

  3. #3
    Join Date
    May 2010
    Posts
    8
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Settings for a particular file

    Does anyone have a small example of using "QSettings::QSettings ( const QString & fileName, Format format, QObject * parent = 0 );" ?
    I have some trouble on using it; in particular I don't understand what is the format for "fileName", also because if I use only the fileName (without path) I can't be sure that the name is unique; if I use the path+fileName and after some time the user change directory of the file with Windows explorer then the relative QSetting can't be found... Thank you.

  4. #4
    Join Date
    Jan 2006
    Location
    Belgium
    Posts
    1,938
    Thanked 268 Times in 268 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Wiki edits
    20

    Default Re: Settings for a particular file


  5. #5
    Join Date
    Apr 2010
    Posts
    769
    Thanks
    1
    Thanked 94 Times in 86 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Default Re: Settings for a particular file

    Since you've acknowledged that the user may move the file to a different directory, and the filename alone doesn't provide unique identification, take a moment and convince yourself that any amount of fiddling with QSettings will fail to do what you want. Unless you can lock down the file's location in a predefined directory structure which never varies, your only alternative is to store your information in the file itself - either internally (the best solution, if possible) or by embedding information in the filename. The latter is also problematic, since the user can rename the file to whatever they want.

    If the files in question are created by you and are unique to your application, store the information internally.

  6. #6
    Join Date
    May 2010
    Posts
    8
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Settings for a particular file

    It is exactly what I wanted to do, but I wanted to be sure there were no other better solutions before starting development. Thanks a lot for the help given.

Similar Threads

  1. How to link static libraries --- in .pro file settings?
    By jiapei100 in forum Qt Programming
    Replies: 1
    Last Post: 7th January 2010, 16:39
  2. XML vs file sotring settings
    By ^NyAw^ in forum Qt Programming
    Replies: 3
    Last Post: 7th May 2009, 16:13
  3. .pro settings for obj subdir
    By bajarangi in forum Newbie
    Replies: 2
    Last Post: 17th April 2009, 14:31
  4. KPart settings?
    By maartenS in forum KDE Forum
    Replies: 1
    Last Post: 26th November 2008, 08:43
  5. qSplitter settings
    By ovidiu.sabou in forum Qt Tools
    Replies: 4
    Last Post: 14th March 2006, 18:24

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.