Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/qt/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 麻烦_C++_Qt - Fatal编程技术网

C++ 麻烦

C++ 麻烦,c++,qt,C++,Qt,我正在使用QSettings函数。一旦在.h文件变量中成功设置 QSettings *settings; 在构造函数cpp中。文件我以这种方式设置变量,以获得像Draw/Input/Cells/Width这样的路径 settings = new QSettings("MySoft", "Star Runner"); settings->beginGroup("Draw"); settings->beginGroup("Input"); settings->beginGroup

我正在使用QSettings函数。一旦在.h文件变量中成功设置

QSettings *settings;
在构造函数cpp中。文件我以这种方式设置变量,以获得像Draw/Input/Cells/Width这样的路径

settings = new QSettings("MySoft", "Star Runner");
settings->beginGroup("Draw");
settings->beginGroup("Input");
settings->beginGroup("Cells");
settings->setValue("width", 80);
settings->endGroup();
settings->endGroup();
settings->endGroup();
问题在于,只有在组织名称声明期间设置为MySoft时,宽度值才正确设置为80:如果您分配了任何其他值,例如foobar,则通过

qDebug() << settings->value("width", "").toString();

宽度键为无值

读取值时,还应开始和结束组。所以你可以试试

qDebug() << settings->value("Draw/Input/Cells/width", "").toString();


settings->valueDraw/Input/Cells/width是否有值?保存和还原键的值时,组织和应用程序名称应相同。您不应期望在另一个组织名称中获得保存的值。QSettings包装了windows上注册表的使用和Linux上ini文件的使用。提供组织和应用程序定义将注册表项或ini文件放在何处。预期会出现这样的行为。请阅读我的问题。问题中的组织名称不清楚调试测试行在代码中的何处执行。在编写值之后,构造函数中的值是否仍在嵌套组中?如果没有,请张贴完整的功能,以澄清您的问题。
settings->beginGroup("Draw");
settings->beginGroup("Input");
settings->beginGroup("Cells");
qDebug() << settings->value("width", "").toString();
settings->endGroup();
settings->endGroup();
settings->endGroup();