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