简体   繁体   English

QSettings(Qt 5.4):setValue无法正常工作

[英]QSettings(Qt 5.4): setValue doesn't work properly

In my .cpp I'm using QSettings. 在我的.cpp中,我正在使用QSettings。
This worked before, in Qt 4.8: 这在Qt 4.8之前有效:

#include <QSettings>


----------


QSettings settings;
settings.setValue("time_axis_direction", 1);
int test_var = settings.value("time_axis_direction").toInt();


----------

In test_var the program returns 0, what's the cause? test_var ,程序返回0,原因是什么?
I used Qt with VS Add-In. 我使用Qt和VS Add-In。

According to the docs , you have to set organization name and application name: 根据文档 ,您必须设置组织名称和应用程序名称:

QCoreApplication::setOrganizationName("My Organization");
QCoreApplication::setApplicationName("My Application");
QSettings settings;

Or right in the constructor: 或者在构造函数中:

QSettings settings("My Organization", "My Application");

This will create HKCU\\SOFTWARE\\My Organization\\My Application registry entry to store your settings (on Windows). 这将创建HKCU\\SOFTWARE\\My Organization\\My Application注册表项以存储您的设置(在Windows上)。

If QCoreApplication::setOrganizationName() and QCoreApplication::setApplicationName() has not been previously called, the QSettings object will not be able to read or write any settings, and status() will return AccessError. 如果先前未调用QCoreApplication :: setOrganizationName()和QCoreApplication :: setApplicationName(),则QSettings对象将无法读取或写入任何设置,status()将返回AccessError。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM