繁体   English   中英

Double 到 QString 并保存在 QJsonDocument 中

[英]Double to QString and save in QJsonDocument

我需要使用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

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

我在 QTCreator 中使用 C++。

这应该对工作

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

暂无
暂无

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

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