[Interest] QJsonDocument::fromVariant failing with list

Thiago Macieira thiago.macieira at intel.com
Wed Jun 9 16:53:23 CEST 2021

On Wednesday, 9 June 2021 07:23:42 PDT Jason H wrote:
> That is what I was expecting. I thought they were just a typedef? (Though I
> am lying there, I know QStringList inherits from QList<QString>) The
> instant case of QList<QVariant> is just a typedef though, so I am confused
> as why it wasn't working. I thought typedefs were indistinguishable?  The
> expressiveness of C++11 initializers of creating objects that end up in
> CBOR and JSON for I/O, and QVariant based trees (incl arrays) for in-app
> databases is just awesome. But then you get someone wielding C++ clumsily
> like me. :-)

You may want to take a look at qtcontainerfwd.h some time. It contains these 

using QStringList = QList<QString>;
using QByteArrayList = QList<QByteArray>;
using QVariantList = QList<QVariant>;
using QVariantMap = QMap<QString, QVariant>;
using QVariantHash = QHash<QString, QVariant>;
using QVariantPair = QPair<QVariant, QVariant>;

So QStringList *is* a QList, not even deriving from it. That wasn't the case 
in Qt 4 and 5, but is fixed for Qt 6. QVariantList has always been 
QList<QVariant> though, since it was introduced in 4.0.

The problem is not that you were using QList<QVariant> over QVariantList. The 
problem is that you introduced a new type.

Thiago Macieira - thiago.macieira (AT) intel.com
  Software Architect - Intel DPG Cloud Engineering

More information about the Interest mailing list