QMetaProperty::typeName: use name from metatype
Except for types marked as unresolved, we're doing it anyway - the only difference is that now we skip looking up the metatype by typeid. [ChangeLog][QMetaProperty][Important Behavior Change] QMetaProperty::typeName returns now always the same name as name() of the corresponding metatype. This can cause a change for enum properties which were not fully-qualified. Change-Id: I1f57743948b7262ac06095d3bbc838d620f6e481 Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> Reviewed-by: Lars Knoll <lars.knoll@qt.io> Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
This commit is contained in:
parent
26e1a0997e
commit
d27d2b5d72
@ -2934,6 +2934,9 @@ const char *QMetaProperty::typeName() const
|
||||
{
|
||||
if (!mobj)
|
||||
return nullptr;
|
||||
// TODO: can the metatype be invalid for dynamic metaobjects?
|
||||
if (const auto mt = metaType(); mt.isValid())
|
||||
return mt.name();
|
||||
return rawTypeNameFromTypeInfo(mobj, data.type());
|
||||
}
|
||||
|
||||
|
@ -1337,14 +1337,15 @@ static int buildMetaObject(QMetaObjectBuilderPrivate *d, char *buf,
|
||||
|
||||
// Output the properties in the class.
|
||||
Q_ASSERT(!buf || dataIndex == pmeta->propertyData);
|
||||
for (const auto &prop : d->properties) {
|
||||
for (QMetaPropertyBuilderPrivate &prop : d->properties) {
|
||||
int name = strings.enter(prop.name);
|
||||
|
||||
int typeInfo;
|
||||
if (QtPrivate::isBuiltinType(prop.type))
|
||||
typeInfo = QMetaType::fromName(prop.type).id();
|
||||
else
|
||||
typeInfo = IsUnresolvedType | strings.enter(prop.type);
|
||||
// try to resolve the metatype again if it was unknown
|
||||
if (!prop.metaType.isValid())
|
||||
prop.metaType = QMetaType::fromName(prop.type);
|
||||
const int typeInfo = prop.metaType.isValid()
|
||||
? prop.metaType.id()
|
||||
: IsUnresolvedType | strings.enter(prop.type);
|
||||
|
||||
int flags = prop.flags;
|
||||
|
||||
@ -1437,7 +1438,7 @@ static int buildMetaObject(QMetaObjectBuilderPrivate *d, char *buf,
|
||||
if (buf) {
|
||||
meta->d.metaTypes = types;
|
||||
for (const auto &prop : d->properties) {
|
||||
QMetaType mt = QMetaType::fromName(prop.type);
|
||||
QMetaType mt = prop.metaType;
|
||||
*types = reinterpret_cast<QtPrivate::QMetaTypeInterface *&>(mt);
|
||||
types++;
|
||||
}
|
||||
|
@ -1933,7 +1933,7 @@ void tst_QObject::property()
|
||||
QVERIFY(mo->indexOfProperty("alpha") != -1);
|
||||
property = mo->property(mo->indexOfProperty("alpha"));
|
||||
QVERIFY(property.isEnumType());
|
||||
QCOMPARE(property.typeName(), "Alpha");
|
||||
QCOMPARE(property.typeName(), "PropertyObject::Alpha");
|
||||
QCOMPARE(property.userType(), QMetaType::fromType<PropertyObject::Alpha>().id());
|
||||
|
||||
QVariant var = object.property("alpha");
|
||||
@ -2015,7 +2015,7 @@ void tst_QObject::property()
|
||||
QVERIFY(mo->indexOfProperty("priority") != -1);
|
||||
property = mo->property(mo->indexOfProperty("priority"));
|
||||
QVERIFY(property.isEnumType());
|
||||
QCOMPARE(property.typeName(), "Priority");
|
||||
QCOMPARE(property.typeName(), "PropertyObject::Priority");
|
||||
QCOMPARE(property.userType(), QMetaType::fromType<PropertyObject::Priority>().id());
|
||||
|
||||
var = object.property("priority");
|
||||
@ -2036,7 +2036,7 @@ void tst_QObject::property()
|
||||
QVERIFY(mo->indexOfProperty("priority") != -1);
|
||||
property = mo->property(mo->indexOfProperty("priority"));
|
||||
QVERIFY(property.isEnumType());
|
||||
QCOMPARE(property.typeName(), "Priority");
|
||||
QCOMPARE(property.typeName(), "PropertyObject::Priority");
|
||||
QCOMPARE(property.type(), QVariant::UserType);
|
||||
QCOMPARE(property.userType(), priorityMetaTypeId);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user