PDA

View Full Version : Error conversion from QMap<QString, QVariantList> to QVariant



alexeyGL
4th July 2013, 12:57
Hello!

I've tried to convert QMap<QString, QVariantList> to QVariant, but I obtained compillation error:


error: conversion from QMap<QString, QVariantList> to non-scalar type 'QVariant' requested

By the way, QMap<QString, QVariant> converts to QVariant fine.

I've looked Qt documentation about QVariant, but didn't find anything about it.
Possibly, the reason is that one container have another one into it.

Could you explain this situation, please?

Added after 29 minutes:

Oh, sorry. Of course such type QMap<QString, QVariantList> is not listed in enum QVariant::Type (Only QMap<QString, QVariant>).

But in Qt5 this enum is obsolete.
Do anyone know, is it works in Qt5? (Unfortunatelly, I could not try it now.)

anda_skoa
4th July 2013, 20:14
QVariant can deal with any type that has certain properties such as being default constructible, copyable and assignable.

For non-built-in types it is necessary to declare them to the Qt meta type system using Q_DECLARE_METATYPE



Q_DECLARE_METATYPE(QMap<QString, QVariantList>);


Cheers,
_

alexeyGL
8th July 2013, 13:14
Thank you!