0

我需要保存低于预设水平的值,使用QJsonDocument. 我有以下代码示例:

(...) 
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));'

它应该保存如下内容:

"below3.67pts":2
"below7.43pts":6
"below9.76pts":10

而是节省:

"below3":Object
   "67pts":2
"below7":Object
   "43pts":6
"below9":Object
   "76pts":10

我得到的问题是我如何保存 doubles 数组gameLevels。但我真的需要将带点的数字保存为字符串。有没有另一种方法可以在不自动创建对象的情况下保存这样的字符串?

我在 QTCreator 中使用 C++。

4

1 回答 1

0

这应该对工作

instantPowerPoints.insert(QString("%1 %2 %3").arg(below).arg(sGL).arg(points), auxPoints);

于 2020-01-07T14:40:43.937 回答