Commit 84aef37a authored by Volker Krause's avatar Volker Krause
Browse files

Check a meta type is a gadget before treating it as such

With Qt6, enum meta types also report a meta object, but that's the one
of the type containing the enum.
parent 4be24036
......@@ -30,8 +30,10 @@ inline bool isA(const QVariant &value)
template <typename T>
inline bool canConvert(const QVariant &value)
{
const auto mo = QMetaType(value.userType()).metaObject();
if (!mo) {
const auto mt = QMetaType(value.userType());
// for enums/flags, this is the enclosing meta object starting with Qt6!
const auto mo = mt.metaObject();
if ((mt.flags() & QMetaType::IsGadget) == 0 || !mo) {
return false;
}
return mo->inherits(&T::staticMetaObject);
......
......@@ -590,7 +590,7 @@ QVariant JsonLdDocument::apply(const QVariant& lhs, const QVariant& rhs)
}
auto pv = prop.readOnGadget(rhs.constData());
if (QMetaType(pv.userType()).metaObject()) {
if ((QMetaType::typeFlags(pv.userType()) & QMetaType::IsGadget) && QMetaType(pv.userType()).metaObject()) {
pv = apply(prop.readOnGadget(lhs.constData()), pv);
}
if (!pv.isNull()) {
......
......@@ -533,6 +533,7 @@ QVariant MergeUtil::merge(const QVariant &lhs, const QVariant &rhs)
auto lv = prop.readOnGadget(lhs.constData());
auto rv = prop.readOnGadget(rhs.constData());
auto mt = rv.userType();
const auto metaType = QMetaType(mt);
if (mt == qMetaTypeId<Airline>()) {
rv = mergeValue(lv.value<Airline>(), rv.value<Airline>());
......@@ -542,7 +543,7 @@ QVariant MergeUtil::merge(const QVariant &lhs, const QVariant &rhs)
rv = mergeValue(lv.toDateTime(), rv.toDateTime());
} else if (mt == qMetaTypeId<Ticket>()) {
rv = mergeValue(lv.value<Ticket>(), rv.value<Ticket>());
} else if (QMetaType(mt).metaObject()) {
} else if ((metaType.flags() & QMetaType::IsGadget) && metaType.metaObject()) {
rv = merge(prop.readOnGadget(lhs.constData()), rv);
}
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment