diff options
author | Fabian Kosmale <fabian.kosmale@qt.io> | 2023-08-11 10:45:51 +0200 |
---|---|---|
committer | Fabian Kosmale <fabian.kosmale@qt.io> | 2024-01-26 14:51:35 +0100 |
commit | ac001bef798b79f4932d7ca8f4fb812159ba75ca (patch) | |
tree | 1cf783aa9235c4cf72e64d3775957ee6d621870c /src/corelib/kernel/qmetaobject.cpp | |
parent | 941afac108aded21ea50caeec0b72291fcad7d59 (diff) |
moc/QMetaProperty: Remove limitation on non-own-class notify signals
The moc generated code does a sanity check that NOTIFY signals actually
exist in the parent class when they cannot be found in the class moc
currently runs on.
The logic there was however too simplistic, and couldn't deal with
signals taking a parameter.
Fix this, and take the opportunity to use a proper static_assert instead
of generating a "normal" compile error.
We do not do any checks for the presence of QPrivateSignal, as the whole
point of QPrivateSignal is that it should be private (and not e.g.
protected).
Moreover, we adjust QMetaProperty::notifySignalIndex to take
single-argument notify methods into consideration as well when
encontering an unresolved notify index.
Fixes: QTBUG-115989
Pick-to: 6.7
Change-Id: I8a056a15777f3132691e207b4b9ab6c2c9b2126d
Reviewed-by: Ivan Solovev <ivan.solovev@qt.io>
Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
Diffstat (limited to 'src/corelib/kernel/qmetaobject.cpp')
-rw-r--r-- | src/corelib/kernel/qmetaobject.cpp | 31 |
1 files changed, 17 insertions, 14 deletions
diff --git a/src/corelib/kernel/qmetaobject.cpp b/src/corelib/kernel/qmetaobject.cpp index 3d0eeb1683..d45673ef25 100644 --- a/src/corelib/kernel/qmetaobject.cpp +++ b/src/corelib/kernel/qmetaobject.cpp @@ -3973,20 +3973,23 @@ int QMetaProperty::notifySignalIndex() const if (!mobj || data.notifyIndex() == std::numeric_limits<uint>::max()) return -1; uint methodIndex = data.notifyIndex(); - if (methodIndex & IsUnresolvedSignal) { - methodIndex &= ~IsUnresolvedSignal; - const QByteArray signalName = stringData(mobj, methodIndex); - const QMetaObject *m = mobj; - const int idx = QMetaObjectPrivate::indexOfMethodRelative<MethodSignal>(&m, signalName, 0, nullptr); - if (idx >= 0) { - return idx + m->methodOffset(); - } else { - qWarning("QMetaProperty::notifySignal: cannot find the NOTIFY signal %s in class %s for property '%s'", - signalName.constData(), mobj->className(), name()); - return -1; - } - } - return methodIndex + mobj->methodOffset(); + if (!(methodIndex & IsUnresolvedSignal)) + return methodIndex + mobj->methodOffset(); + methodIndex &= ~IsUnresolvedSignal; + const QByteArray signalName = stringData(mobj, methodIndex); + const QMetaObject *m = mobj; + // try 0-arg signal + int idx = QMetaObjectPrivate::indexOfMethodRelative<MethodSignal>(&m, signalName, 0, nullptr); + if (idx >= 0) + return idx + m->methodOffset(); + // try 1-arg signal + QArgumentType argType(typeId()); + idx = QMetaObjectPrivate::indexOfMethodRelative<MethodSignal>(&m, signalName, 1, &argType); + if (idx >= 0) + return idx + m->methodOffset(); + qWarning("QMetaProperty::notifySignal: cannot find the NOTIFY signal %s in class %s for property '%s'", + signalName.constData(), mobj->className(), name()); + return -1; } // This method has been around for a while, but the documentation was marked \internal until 5.1 |