QQmlProperty: fix signal handler warning

It should only be emitted if we find a signal of that name.

Pick-to: 6.7 6.6 6.5
Fixes: QTBUG-118710
Change-Id: I15cf92c03dd7b46805e5a69078ca2beb6c862293
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
This commit is contained in:
Fabian Kosmale 2023-11-02 11:06:14 +01:00 committed by Ulf Hermann
parent 37ef144704
commit 9d10b79566
3 changed files with 30 additions and 6 deletions

View File

@ -411,13 +411,14 @@ void QQmlPropertyPrivate::initProperty(QObject *obj, const QString &name,
} else {
signalName = QQmlSignalNames::badHandlerNameToSignalName(terminal);
if (signalName) {
qWarning()
<< terminal
<< "is not a properly capitalized signal handler name."
<< QQmlSignalNames::signalNameToHandlerName(*signalName)
<< "would be correct.";
if (findSignal(*signalName))
if (findSignal(*signalName)) {
qWarning()
<< terminal
<< "is not a properly capitalized signal handler name."
<< QQmlSignalNames::signalNameToHandlerName(*signalName)
<< "would be correct.";
return;
}
}
}

View File

@ -0,0 +1,9 @@
import QtQml
QtObject {
id: root
property int onlineStatus
property Binding b: Binding {
root.onlineStatus: 12
}
}

View File

@ -222,6 +222,8 @@ private slots:
void invalidateQPropertyChangeTriggers();
void propertyStartsWithOn();
private:
QQmlEngine engine;
};
@ -2590,6 +2592,18 @@ void tst_qqmlproperty::invalidateQPropertyChangeTriggers()
}));
}
void tst_qqmlproperty::propertyStartsWithOn()
{
QTest::failOnWarning("\"onlineStatus\" is not a properly capitalized signal handler name. "
"\"onLineStatus\" would be correct.");
QQmlEngine engine;
QQmlComponent component(&engine, testFileUrl("propertyStartsWithOn.qml"));
QVERIFY2(component.isReady(), qPrintable(component.errorString()));
QScopedPointer<QObject> root(component.create());
QVERIFY(!root.isNull());
QCOMPARE(root->property("onlineStatus").toInt(), 12);
}
QTEST_MAIN(tst_qqmlproperty)
#include "tst_qqmlproperty.moc"