Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Change path of saving file QSettings
QtWS25 Last Chance

Change path of saving file QSettings

Scheduled Pinned Locked Moved Unsolved General and Desktop
4 Posts 3 Posters 2.1k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • K Offline
    K Offline
    Kaznachei
    wrote on last edited by
    #1

    I have object of QSettings.

    QSettings settings("save.ini", QSettings::IniFormat);

    but what if i wanna to change path? For example i want to settings saves my values in "../anothersave.ini". How can i do that?

    J.HilkJ 1 Reply Last reply
    0
    • K Kaznachei

      I have object of QSettings.

      QSettings settings("save.ini", QSettings::IniFormat);

      but what if i wanna to change path? For example i want to settings saves my values in "../anothersave.ini". How can i do that?

      J.HilkJ Offline
      J.HilkJ Offline
      J.Hilk
      Moderators
      wrote on last edited by
      #2

      hi @Kaznachei

      when you don't specify a path in the QSettings constructor, than the file will be relative to exe executable.

      Therefore

      QSettings settings("save.ini", QSettings::IniFormat); == QSettings settings("path/toExecutable/save.ini", QSettings::IniFormat);
      

      Therefore you can use applicationDirPath to get the path to your exe

      QSettings settings("save.ini", QSettings::IniFormat); == QSettings settings(QCoreApplication::QCoreApplication::applicationDirPath() + "/save.ini", QSettings::IniFormat);
      

      Now, knowing that. your an save the path in a QString and manipulate it, so that it points to an other folder and than pass that one in the Settings constructor.


      Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


      Q: What's that?
      A: It's blue light.
      Q: What does it do?
      A: It turns blue.

      1 Reply Last reply
      3
      • K Offline
        K Offline
        Kaznachei
        wrote on last edited by
        #3

        I got it. But i asked how can i change path after initialization?

        1 Reply Last reply
        0
        • SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on last edited by
          #4

          Hi,

          If by that you mean you want to change the path of an existing QSettings object, you can't.

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

          1 Reply Last reply
          1

          • Login

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • Users
          • Groups
          • Search
          • Get Qt Extensions
          • Unsolved