简体   繁体   中英

Double to QString and save in QJsonDocument

I need to save values ​​below pre-set levels, using 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 . 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.

这应该对工作

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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