[英]Double to QString and save in QJsonDocument
I need to save values below pre-set levels, using QJsonDocument
.我需要使用
QJsonDocument
保存低于预设水平的值。 I have the following example of code:我有以下代码示例:
(...)
gameLevels= {3.67, 7.43, 9.76};
while(gameLevels[i] <= x)
{
for(...)
{
//do something and calculate auxPoints.
}
QString sGL = QString::number(gameLevels[i]);
QString below = "below";
QString points = "pts";
instantPowerPoints.insert(below + sGL+ points , auxPoints);
i++;
(...)
}
emit saveData(QJsonDocument(instantPowerPoints));'
It should save something like:它应该保存如下内容:
"below3.67pts":2
"below7.43pts":6
"below9.76pts":10
But instead is saving:但取而代之的是节省:
"below3":Object
"67pts":2
"below7":Object
"43pts":6
"below9":Object
"76pts":10
I get the problem is how I save the array of doubles gameLevels
.我的问题是我如何保存双打
gameLevels
数组。 But I really need to have the number with the dot save as a string.但我真的需要将带点的数字另存为字符串。 Is there another way to save the string like this without automatically creating the object?
有没有另一种方法可以在不自动创建对象的情况下保存这样的字符串?
I am using C++ in QTCreator.我在 QTCreator 中使用 C++。
这应该对工作
instantPowerPoints.insert(QString("%1 %2 %3").arg(below).arg(sGL).arg(points), auxPoints);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.