QQmlOpenMetaObject: Clarify signal numbering
When creating a property and a signal, the indices can be different. Task-number: QTBUG-102454 Change-Id: Id459d6476a6b1dc6c3d524ed3fe34d8d5535a3af Reviewed-by: Andrei Golubev <andrei.golubev@qt.io> Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
This commit is contained in:
parent
871024cdce
commit
4a6cabf3eb
|
@ -129,13 +129,13 @@ void QQmlOpenMetaObjectType::createProperties(const QVector<QByteArray> &names)
|
|||
|
||||
int QQmlOpenMetaObjectType::createProperty(const QByteArray &name)
|
||||
{
|
||||
int id = d->mob.propertyCount();
|
||||
d->mob.addSignal("__" + QByteArray::number(id) + "()");
|
||||
QMetaPropertyBuilder build = d->mob.addProperty(name, "QVariant", id);
|
||||
propertyCreated(id, build);
|
||||
const int signalIdx = d->mob.addSignal(
|
||||
"__" + QByteArray::number(d->mob.propertyCount()) + "()").index();
|
||||
QMetaPropertyBuilder build = d->mob.addProperty(name, "QVariant", signalIdx);
|
||||
propertyCreated(build.index(), build);
|
||||
free(d->mem);
|
||||
d->mem = d->mob.toMetaObject();
|
||||
d->names.insert(name, id);
|
||||
d->names.insert(name, build.index());
|
||||
QSet<QQmlOpenMetaObject*>::iterator it = d->referers.begin();
|
||||
while (it != d->referers.end()) {
|
||||
QQmlOpenMetaObject *omo = *it;
|
||||
|
@ -145,7 +145,7 @@ int QQmlOpenMetaObjectType::createProperty(const QByteArray &name)
|
|||
++it;
|
||||
}
|
||||
|
||||
return d->propertyOffset + id;
|
||||
return d->propertyOffset + build.index();
|
||||
}
|
||||
|
||||
void QQmlOpenMetaObjectType::propertyCreated(int id, QMetaPropertyBuilder &builder)
|
||||
|
|
|
@ -65,6 +65,7 @@ private slots:
|
|||
void lookupsInSubTypes();
|
||||
void freeze();
|
||||
void cachedSignals();
|
||||
void signalIndices();
|
||||
};
|
||||
|
||||
class LazyPropertyMap : public QQmlPropertyMap, public QQmlParserStatus
|
||||
|
@ -636,6 +637,47 @@ void tst_QQmlPropertyMap::cachedSignals()
|
|||
QCOMPARE(o->property("text").toString(), u"final"_qs);
|
||||
}
|
||||
|
||||
class NastyMap: public QQmlPropertyMap
|
||||
{
|
||||
Q_OBJECT
|
||||
Q_PROPERTY(int a READ a WRITE setA NOTIFY aChanged)
|
||||
Q_PROPERTY(int b MEMBER m_b CONSTANT)
|
||||
|
||||
public:
|
||||
|
||||
int a() const { return m_a; }
|
||||
void setA(int a)
|
||||
{
|
||||
if (a != m_a) {
|
||||
m_a = a;
|
||||
emit aChanged();
|
||||
}
|
||||
}
|
||||
|
||||
signals:
|
||||
void aChanged();
|
||||
void extraSignal();
|
||||
|
||||
private:
|
||||
int m_a = 0;
|
||||
int m_b = 7;
|
||||
};
|
||||
|
||||
void tst_QQmlPropertyMap::signalIndices()
|
||||
{
|
||||
NastyMap map;
|
||||
map.insert(QLatin1String("key1"), 100);
|
||||
const QMetaObject *mo = map.metaObject();
|
||||
const int propertyIndex = mo->indexOfProperty("key1");
|
||||
const QMetaProperty property = mo->property(propertyIndex);
|
||||
const int signalIndex = property.notifySignalIndex();
|
||||
const QMetaMethod method = mo->method(signalIndex);
|
||||
|
||||
QSignalSpy spy(&map, method);
|
||||
map.insert(QLatin1String("key1"), 200);
|
||||
QCOMPARE(spy.count(), 1);
|
||||
}
|
||||
|
||||
QTEST_MAIN(tst_QQmlPropertyMap)
|
||||
|
||||
#include "tst_qqmlpropertymap.moc"
|
||||
|
|
Loading…
Reference in New Issue