[Development] Serialising UI state in QML via QSettings and JSON: QByteArray vs QString

Edward Welbourne edward.welbourne at qt.io
Mon Oct 29 19:30:47 CET 2018


Mitch Curtis (29 October 2018 17:42)
> To solve #2, I first tried simply saving a QVariant containing a
> QByteArray (the contents of which were QDataStream's output). This
> didn't work because Qt's JSON implementation doesn't support
> QByteArray; it only supports QString. That is, calling
> QJsonObject::fromVariantMap(map) where "map" contains a QVariant
> containing a QByteArray will result in the corresponding JSON value
> being invalid/null.

I'm not sure where JSON got involved in that, but if you can manage to
use CBOR instead, it's just as happy with QByteArray as with QString
(and round-trips them to QByteArray, IIRC).  For details, see
qtbase/src/corelib/serialization/qcborstream.h

I've also no idea how well it plays with QSettings; hopefully you know
enough to work it out from the QCbor API ...

	Eddy.



More information about the Development mailing list