27 int main(
int argc,
char const *argv[])
41 auto value1 = QMPointer<QMJsonValue>(
new QMJsonValue(5.5));
42 auto value2 = QMPointer<QMJsonValue>(
new QMJsonValue(
"Hello"));
43 auto value3 = QMPointer<QMJsonValue>(
new QMJsonValue(
true));
44 auto array = QMPointer<QMJsonArray>(
new QMJsonArray());
45 auto object = QMPointer<QMJsonObject>(
new QMJsonObject());
47 auto document = QMPointer<QMJsonValue>(
new QMJsonValue(tree));
49 array->append(value1);
50 array->append(value2);
51 array->append(value3);
53 object->insert(
"key1", value1);
54 object->insert(
"key2", value2);
55 object->insert(
"key3", value3);
57 tree->insert(
"array", array);
58 tree->insert(
"object",
object);
60 auto complexValue1 = QMPointer<QMJsonValue>(
new QMJsonValue(QColor(
"red")));
61 auto complexValue2 = QMPointer<QMJsonValue>(
new QMJsonValue(QPoint(2, 2)));
62 auto complexValue3 = QMPointer<QMJsonValue>(
new QMJsonValue(QRect(5, 5, 3, 3)));
63 auto complexValue4 = QMPointer<QMJsonValue>(
new QMJsonValue(QSize(10, 10)));
71 qDebug() <<
" " << value1;
72 qDebug() <<
" " << value2;
73 qDebug() <<
" " << value3;
75 qDebug() <<
" " << array;
76 qDebug() <<
" " << object;
78 qDebug() <<
" " << array->toDouble(0);
79 qDebug() <<
" " << array->toString(1);
80 qDebug() <<
" " << array->toBool(2);
82 qDebug() <<
" " << array->value(0);
83 qDebug() <<
" " << array->value(1);
84 qDebug() <<
" " << array->value(2);
86 qDebug() <<
" " <<
object->toDouble(
"key1");
87 qDebug() <<
" " <<
object->toString(
"key2");
88 qDebug() <<
" " <<
object->toBool(
"key3");
90 qDebug() <<
" " <<
object->value(
"key1");
91 qDebug() <<
" " <<
object->value(
"key2");
92 qDebug() <<
" " <<
object->value(
"key3");
100 qDebug() <<
"Invalid:";
102 qDebug() <<
" " << array->toString(0);
103 qDebug() <<
" " << array->toBool(1);
104 qDebug() <<
" " << array->toDouble(2);
106 qDebug() <<
" " << array->toDouble(3);
107 qDebug() <<
" " << array->toString(4);
108 qDebug() <<
" " << array->toBool(5);
110 qDebug() <<
" " << array->value(6);
111 qDebug() <<
" " << array->value(7);
112 qDebug() <<
" " << array->value(8);
114 qDebug() <<
" " <<
object->toString(
"key1");
115 qDebug() <<
" " <<
object->toBool(
"key2");
116 qDebug() <<
" " <<
object->toDouble(
"key3");
118 qDebug() <<
" " <<
object->toDouble(
"key4");
119 qDebug() <<
" " <<
object->toString(
"key5");
120 qDebug() <<
" " <<
object->toBool(
"key6");
122 qDebug() <<
" " <<
object->value(
"key7");
123 qDebug() <<
" " <<
object->value(
"key8");
124 qDebug() <<
" " <<
object->value(
"key9");
134 value1->fromDouble(10.3);
135 value2->fromString(
"World");
136 value3->fromBool(
false);
138 qDebug() <<
" " << value1;
139 qDebug() <<
" " << value2;
140 qDebug() <<
" " << value3;
148 qDebug() <<
" " << tree;
172 qDebug() <<
"Complex Values:";
173 qDebug() << complexValue1;
174 qDebug() << complexValue2;
175 qDebug() << complexValue3;
176 qDebug() << complexValue4;
180 qDebug() << complexValue1->is<QColor>();
181 qDebug() << complexValue2->is<QPoint>();
182 qDebug() << complexValue3->is<QRect>();
183 qDebug() << complexValue4->is<QSize>();
187 qDebug() << complexValue1->to<QColor>(QColor());
188 qDebug() << complexValue2->to<QPoint>(QPoint());
189 qDebug() << complexValue3->to<QRect>(QRect());
190 qDebug() << complexValue4->to<QSize>(QSize());
194 qDebug() << complexValue1->from<QColor>(QColor(
"blue"));
195 qDebug() << complexValue2->from<QPoint>(QPoint(4, 8));
196 qDebug() << complexValue3->from<QRect>(QRect(15, 16, 23, 42));
197 qDebug() << complexValue4->from<QSize>(QSize(21, 12));
200 qDebug() <<
"Complex to JSON:";
201 qDebug() << qPrintable(complexValue1->toJson());
202 qDebug() << qPrintable(complexValue2->toJson());
203 qDebug() << qPrintable(complexValue3->toJson());
204 qDebug() << qPrintable(complexValue4->toJson());
207 qDebug() <<
"Complex from JSON:";
static QMPointer< QMJsonValue > fromJson(const QString &json)
int main(int argc, char const *argv[])
static QMPointer< QMJsonValue > fromJsonFile(const QString &filename)
static void registerFromComplexJson(const QString &qmjsontype, FromComplexJsonFunc func)