Slavenskij
Slavenskij

Reputation: 649

Qt QJsonDocument::fromBinaryData() does not work

Here is simple code:

QByteArray ba  = jdoc.toBinaryData();
QJsonDocument jdoc2;
jdoc2.fromBinaryData(ba);
qDebug() << jdoc.isNull();
qDebug() << jdoc2.isNull();

Result: jdoc is not null, but jdoc2 is null. What am I doing wrong? It looks like jdoc2.fromBinaryData(ba); does not work at all. I use Qt 5.5.0

Upvotes: 2

Views: 884

Answers (2)

Dmitry Sazonov
Dmitry Sazonov

Reputation: 8994

QJsonDocument::fromBinaryData is a static method. You need to write:

jdoc2 = QJsonDocument::fromBinaryData( ba );

Upvotes: 5

rocambille
rocambille

Reputation: 15976

fromBinaryData is a static function: your call does'nt affect jdoc2. Try the following instead:

QByteArray ba  = jdoc.toBinaryData();
QJsonDocument jdoc2 = QJsonDocument::fromBinaryData(ba);

Upvotes: 3

Related Questions