QVariant: fix conversions of Q_ENUM that are QFlags<> to string
The doc of QMetaEnum::valueToKey() says to use ::valueToKeys() instead for flag types. Pick-to: 6.4 Change-Id: I48e5ba47324137f2ce2710f1d876e93e7c562e9f Reviewed-by: Thiago Macieira <thiago.macieira@intel.com> Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
This commit is contained in:
parent
ac22743f21
commit
54aa7e75b8
@ -1945,11 +1945,19 @@ static bool convertFromEnum(QMetaType fromType, const void *from, QMetaType toTy
|
|||||||
#ifndef QT_NO_QOBJECT
|
#ifndef QT_NO_QOBJECT
|
||||||
QMetaEnum en = metaEnumFromType(fromType);
|
QMetaEnum en = metaEnumFromType(fromType);
|
||||||
if (en.isValid()) {
|
if (en.isValid()) {
|
||||||
const char *key = en.valueToKey(ll);
|
if (en.isFlag()) {
|
||||||
if (toType.id() == QMetaType::QString)
|
const QByteArray keys = en.valueToKeys(ll);
|
||||||
*static_cast<QString *>(to) = QString::fromUtf8(key);
|
if (toType.id() == QMetaType::QString)
|
||||||
else
|
*static_cast<QString *>(to) = QString::fromUtf8(keys);
|
||||||
*static_cast<QByteArray *>(to) = key;
|
else
|
||||||
|
*static_cast<QByteArray *>(to) = keys;
|
||||||
|
} else {
|
||||||
|
const char *key = en.valueToKey(ll);
|
||||||
|
if (toType.id() == QMetaType::QString)
|
||||||
|
*static_cast<QString *>(to) = QString::fromUtf8(key);
|
||||||
|
else
|
||||||
|
*static_cast<QByteArray *>(to) = key;
|
||||||
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
@ -4753,6 +4753,8 @@ void tst_QVariant::metaEnums()
|
|||||||
|
|
||||||
testVariantMeta(Qt::RichText, &ok, "RichText");
|
testVariantMeta(Qt::RichText, &ok, "RichText");
|
||||||
testVariantMeta(Qt::Alignment(Qt::AlignBottom), &ok, "AlignBottom");
|
testVariantMeta(Qt::Alignment(Qt::AlignBottom), &ok, "AlignBottom");
|
||||||
|
testVariantMeta(Qt::Alignment(Qt::AlignHCenter | Qt::AlignBottom), &ok,
|
||||||
|
"AlignHCenter|AlignBottom");
|
||||||
}
|
}
|
||||||
|
|
||||||
void tst_QVariant::nullConvert()
|
void tst_QVariant::nullConvert()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user