我尝试使用QSettings并编写了一些测试。
if(QFile("C:/Users/test/network.ini").exists()){
QSettings settings("C:/Users/test/network.ini", QSettings::IniFormat);
settings.sync();
settings.beginGroup("Network");
settings.setValue("Port",9999);
settings.endGroup();
settings.sync();
settings.beginGroup("Network");
int port = settings.value("Port").toInt();
settings.endGroup();
settings.sync();
qDebug() << port;
return port;
}
我的Ini文件看起来像这样:
[Network]
Port=4444
文件路径正确但我仍然没有结果。 有什么想法吗?
答案 0 :(得分:-1)
错误是由Qt 5.4.2中的qsettings.h引起的。
原始代码是:
enum Format {
IniFormat,
IniFormat,
InvalidFormat = 16,
CustomFormat1,
CustomFormat2,
CustomFormat3,
CustomFormat4,
CustomFormat5,
CustomFormat6,
CustomFormat7,
CustomFormat8,
CustomFormat9,
CustomFormat10,
CustomFormat11,
CustomFormat12,
CustomFormat13,
CustomFormat14,
CustomFormat15,
CustomFormat16
};
我把它改成
enum Format {
NativeFormat,
IniFormat,
InvalidFormat = 16,
CustomFormat1,
CustomFormat2,
CustomFormat3,
CustomFormat4,
CustomFormat5,
CustomFormat6,
CustomFormat7,
CustomFormat8,
CustomFormat9,
CustomFormat10,
CustomFormat11,
CustomFormat12,
CustomFormat13,
CustomFormat14,
CustomFormat15,
CustomFormat16
};
一切顺利。