#include #define TEST_ITERATIONS 1000 int main(int argc, char *argv[]) { bool failure(false); qsrand(QTime::currentTime().msec()); for (int test= 0; (test < TEST_ITERATIONS) && (!failure); test++) { // Stuff 17 significant decimal digits (from 1 to 9) in aNumberWithManyDigits QByteArray aNumberWithManyDigits("0."); for (int i= 0; i < 17; i++) { aNumberWithManyDigits.append(QByteArray::number((qrand() % 9) + 1)); } double d1(aNumberWithManyDigits.toDouble()); // Store the value in a QJsonObject and use toJson() method to obtain a JSON parseable object QJsonObject jObject; jObject.insert("a nice double value", QJsonValue(d1)); QJsonDocument jDocument1(jObject); QByteArray a(jDocument1.toJson()); // Parse back the JSON object into a new QJsonDocument QJsonDocument jDocument2(QJsonDocument::fromJson(a)); // Obtain the stored value double d2(jDocument2.object().value("a nice double value").toDouble()); failure = (d1 != d2); } if (failure) { qDebug() << "Test failed"; } else { qDebug() << "Test passed"; } return 0; }