Skip to content

Commit

Permalink
QMetaProperty::typeName: use name from metatype
Browse files Browse the repository at this point in the history
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 <[email protected]>
Reviewed-by: Lars Knoll <[email protected]>
Reviewed-by: Ulf Hermann <[email protected]>
  • Loading branch information
Inkane committed Nov 30, 2020
1 parent 26e1a09 commit d27d2b5
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 10 deletions.
3 changes: 3 additions & 0 deletions src/corelib/kernel/qmetaobject.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}

Expand Down
15 changes: 8 additions & 7 deletions src/corelib/kernel/qmetaobjectbuilder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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++;
}
Expand Down
6 changes: 3 additions & 3 deletions tests/auto/corelib/kernel/qobject/tst_qobject.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down Expand Up @@ -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");
Expand All @@ -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);

Expand Down

0 comments on commit d27d2b5

Please sign in to comment.