QSettings - where is the location of the ini file?

前端 未结 9 2047
悲哀的现实
悲哀的现实 2021-02-03 21:45

I\'m using QSettings to store some data as ini file in Windows. I want to see the ini file, but I don\'t know what is the location of the ini file.

This is

相关标签:
9条回答
  • 2021-02-03 21:57

    On Mac OSX, I found the file under at ~/Library/Preferences

    The QSettings class provides persistent platform-independent application settings. Users normally expect an application to remember its settings (window sizes and positions, options, etc.) across sessions. This information is often stored in the system registry on Windows, and in XML preferences files on Mac OS X. On Unix systems, in the absence of a standard, many applications (including the KDE applications) use INI text files

    http://doc.qt.io/archives/qt-4.7/qsettings.html

    0 讨论(0)
  • 2021-02-03 22:03

    To print out the exact location of your settings file use method fileName method of QSettings class.

    QSettings settings("folderName", "fileName");
    qDebug() << settings.fileName();
    

    Console output looks then like:

    /home/user/.config/folderName/fileName.conf
    
    0 讨论(0)
  • 2021-02-03 22:04

    I think you'll find everything you're looking for here : http://doc.qt.io/archives/qt-4.7/qsettings.html

    It's plateform specific, see under :

    Platform-Specific Notes Locations Where Application Settings Are Stored

    You can store Settings in files as well :

    QSettings settings("/home/petra/misc/myapp.ini",
                    QSettings::IniFormat);
    
    0 讨论(0)
  • 2021-02-03 22:07

    in windows path is like below: C:\Users\user_name\AppData\Roaming\bbb

    0 讨论(0)
  • 2021-02-03 22:12

    If you create a QSettings without giving any specific path, the ini file will be located in the application path.

    QSettings Settings("myapp.ini", QSettings::IniFormat);
    Settings.setValue("Test", "data");
    
    //...
    qDebug() << QApplication::applicationDirPath();
    

    Be careful though : the application path might change : for instance, if you are developping your app with Qt Creator, in debug mode, the application path is in the /debug subfolder.

    If you are running it in release mode, the application path is in the /release subfolder.

    And when your application is deployed, by default, the application path is in the same folder as the executable (at least for Windows).

    0 讨论(0)
  • 2021-02-03 22:14

    On Windows without providing an ini filename, you'll find the data in the registry. Using this code snippet:

        int red = color.red();
        int green = color.green();
        int blue = color.blue();
        QSettings settings("Joe", "SettingsDemo");
        qDebug() << settings.fileName();
        settings.beginGroup("ButtonColor");
        settings.setValue("button1r", red);
        settings.setValue("button1g", green);
        settings.setValue("button1b", blue);
        settings.endGroup();
    

    After running this code, you'll see the output:

    "\\HKEY_CURRENT_USER\\Software\\Joe\\SettingsDemo"

    Now, opening the regedit tool and following the path list you got: 1

    0 讨论(0)
提交回复
热议问题