簡體   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