fenix fenix - 1 year ago 184
C++ Question

How do I convert QMap<QString, QMap<QString, int> > to a QVariant?

(needed for
class) supports creation from
QMap<QString, QVariant>

But trying to initialise something like this:

QMap<QString, QVariant(QMap<QString, QVariant>)> i;

Gives the error:

function returning a function.

So then I tried the
QMap<QString, QVariant>
overload for
and got

error: no matching function for call to
QVariant::QVariant(QMap<QString, QMap<QString, int> >&)

Now I tried a typecast:

QMap<QString, (QVariant)QMap<QString, QVariant> > i;

and got

template argument 2 is invalid

invalid type in declaration before '
' token

So what's the required voodoo to convert a nested
to a

Answer Source

The error being reported is that QVariant(...) is not a type, but a function (c-tor).

You should have just used: Map<QString, QVariant> i; and used QVariant(QMap<QString, QVariant>) only when assigning values to the map. The point is QVariant is anything really. So a map of QVariants, can have an int in one position (contained in the QVariant) and a QDate in another. So when declaring the type, you can't specify which types you want QVariant to hold.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download