Solved QVariant backward conversion. How?
-
Hello all!
I have QVariantList and I need to convert every element of this list to the pure Qt data type from QVariant automatically. Kind of backward convesion to original type from QVariant. Something like this:if (element.isInt()) { ... } if (element.isQString()) { ... } if (element.isAnyQVariant()) { ... } ...
Not casting. Casting is statically defining type. I need dynamical function. I need kind of "isType" function. Is there any?
-
You can do
if (element.type() == qMetaTypeId<SomeType>()) { ... }
. -
edit sorry my bad @bogong you
cancan't use https://doc.qt.io/qt-5/qvariant.html#canConvert -
@LeLev
canConvert
is not exactly useful for detecting type. It will, for example, happily return true for convertingint
toQString
. -
@Chris-Kawa got it , thx
-
@Chris-Kawa Thx a lot. Issue closed.