-
Bug
-
Resolution: Won't Do
-
P3: Somewhat important
-
None
-
6.8.5, 6.10.0
Code
#include <QVariant> #include <QMetaType> #include <QDebug> static void checkAndConvert(QVariant &var, QMetaType toType) { qDebug(""); qDebug() << "Can convert to" << toType << "?" << var.canConvert(toType); qDebug() << "Conversion successful?" << var.convert(toType); qDebug() << "New value:" << var; } int main() { QVariant var = QVariant::fromValue(quint8(55)); // 55 == 0x37 == ASCII representation for '7' QMetaType origType = var.metaType(); qDebug() << "Original value:" << var; checkAndConvert(var, QMetaType(QMetaType::QString)); checkAndConvert(var, origType); }
Outcomes
Original value: QVariant(uchar, 55) Can convert to QMetaType(QString) ? true Conversion successful? true New value: QVariant(QString, "7") Can convert to QMetaType(uchar) ? true Conversion successful? true New value: QVariant(uchar, 7)
Questions
- Do we want to support conversion from QMetaType::(U)Char to QMetaType::QString? (Note: In Qt 5.15, QVariant::fromValue(quint8(55)).canConvert(QVariant::String) == false)
- If so, shouldn't the conversion behave in such a way that the final value equals the original value in the test above? (e.g. the first conversion to QString yields "55" instead of "7")