Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to convert QVariant to QJsonValue?

Tags:

c++

qt

qjson

How to convert QVariant to QJsonValue? I know QVariant provide the toJsonValue function, but it did not perform as expected.

For example:

qDebug()<<QVariant(1.0).toJsonValue();
qDebug()<<QVariant("test").toJsonValue();

Both return:

QJsonValue(null)
QJsonValue(null)

Expect output:

QJsonValue(double, 1)
QJsonValue(string, "test")
like image 443
JustWe Avatar asked Oct 15 '25 15:10

JustWe


1 Answers

You can use this static function too:

QJsonValue::fromVariant( myVariant )

Check this link for more info.

like image 162
Musa Avatar answered Oct 18 '25 07:10

Musa