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>()) { ... }. -
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?
-
edit sorry my bad @bogong you
cancan't use https://doc.qt.io/qt-5/qvariant.html#canConvert@LeLev
canConvertis not exactly useful for detecting type. It will, for example, happily return true for convertinginttoQString. -
@LeLev
canConvertis not exactly useful for detecting type. It will, for example, happily return true for convertinginttoQString.@Chris-Kawa got it , thx
-
You can do
if (element.type() == qMetaTypeId<SomeType>()) { ... }.@Chris-Kawa Thx a lot. Issue closed.