关于Qt的QSetting

QSettings::QSettings(const QString &fileName, Format format, QObject *parent = Q_NULLPTR)

Constructs a QSettings object for accessing the settings stored in the file called fileName, with parent parent. If the file doesn't already exist, it is created. 

实际发现根本不会创建文件,除非写数据了才会创建,因此如果想利用此接口创建文件,则需要使用下方的代码示例

If format is QSettings::NativeFormat, the meaning of fileName depends on the platform. On Unix, fileName is the name of an INI file. On macOS and iOS, fileName is the name of a .plist file. On Windows, fileName is a path in the system registry.

If format is QSettings::IniFormat, fileName is the name of an INI file.

Warning: This function is provided for convenience. It works well for accessing INI or .plist files generated by Qt, but might fail on some syntaxes found in such files originated by other programs. In particular, be aware of the following limitations:

  • QSettings provides no way of reading INI "path" entries, i.e., entries with unescaped slash characters. (This is because these entries are ambiguous and cannot be resolved automatically.)
  • In INI files, QSettings uses the @ character as a metacharacter in some contexts, to encode Qt-specific data types (e.g., @Rect), and might therefore misinterpret it when it occurs in pure INI files.


    QSettings settings("E:/testd.ini",QSettings::IniFormat);
    settings.setValue("value",0);

    settings.sync();

    settings.clear();

你可能感兴趣的:(QT)