Skip to content

Commit

Permalink
QMetaObjectBuilder: fix addProperty() recording of the property type
Browse files Browse the repository at this point in the history
Issue introduced by commit 465701b.

[ChangeLog][QtCore][QMetaObjectBuilder] Fixed a bug that would cause
addProperty() to use the incorrect type for the property if the
property's name matched a valid type registered with QMetaType.

Change-Id: Ic15405335d804bdea761fffd16d402f2c9611f30
Reviewed-by: Fabian Kosmale <[email protected]>
(cherry picked from commit 8de0493)
Reviewed-by: Qt Cherry-pick Bot <[email protected]>
  • Loading branch information
thiagomacieira authored and Qt Cherry-pick Bot committed Feb 16, 2022
1 parent 3888037 commit b3d19fb
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/corelib/kernel/qmetaobjectbuilder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -558,7 +558,7 @@ QMetaMethodBuilder QMetaObjectBuilder::addConstructor(const QMetaMethod &prototy
QMetaPropertyBuilder QMetaObjectBuilder::addProperty(const QByteArray &name, const QByteArray &type,
int notifierId)
{
return addProperty(name, type, QMetaType::fromName(name), notifierId);
return addProperty(name, type, QMetaType::fromName(type), notifierId);
}

/*!
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1641,17 +1641,19 @@ void tst_QMetaObjectBuilder::classNameFirstInStringData()
}

struct MyFoo {};
struct myParameter {};

void tst_QMetaObjectBuilder::propertyMetaType()
{
qRegisterMetaType<myParameter>();
QMetaType meta = QMetaType::fromType<MyFoo>();
auto metaId = meta.id();
QMetaObjectBuilder builder;
builder.setClassName("Test");
builder.addProperty("test", "MyFoo");
builder.addProperty("myParameter", "MyFoo");
auto mo = builder.toMetaObject();

QMetaProperty metaProp = mo->property(mo->indexOfProperty("test"));
QMetaProperty metaProp = mo->property(mo->indexOfProperty("myParameter"));
QCOMPARE(metaProp.typeName(), meta.name());
QCOMPARE(metaProp.typeId(), metaId);
QCOMPARE(metaProp.metaType(), meta);
Expand Down

0 comments on commit b3d19fb

Please sign in to comment.