aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/qml/qml/qqmlproperty.cpp9
-rw-r--r--src/qml/types/qqmlconnections.cpp3
-rw-r--r--tests/auto/qml/qqmlconnections/data/underscore.qml14
-rw-r--r--tests/auto/qml/qqmlconnections/tst_qqmlconnections.cpp15
-rw-r--r--tests/auto/qml/qqmlproperty/tst_qqmlproperty.cpp20
5 files changed, 58 insertions, 3 deletions
diff --git a/src/qml/qml/qqmlproperty.cpp b/src/qml/qml/qqmlproperty.cpp
index d191d07258..86cb606f83 100644
--- a/src/qml/qml/qqmlproperty.cpp
+++ b/src/qml/qml/qqmlproperty.cpp
@@ -353,10 +353,15 @@ void QQmlPropertyPrivate::initProperty(QObject *obj, const QString &name)
if (terminal.count() >= 3 &&
terminal.at(0) == QLatin1Char('o') &&
terminal.at(1) == QLatin1Char('n') &&
- terminal.at(2).isUpper()) {
+ (terminal.at(2).isUpper() || terminal.at(2) == '_')) {
QString signalName = terminal.mid(2).toString();
- signalName[0] = signalName.at(0).toLower();
+ int firstNon_;
+ int length = signalName.length();
+ for (firstNon_ = 0; firstNon_ < length; ++firstNon_)
+ if (signalName.at(firstNon_) != '_')
+ break;
+ signalName[firstNon_] = signalName.at(firstNon_).toLower();
// XXX - this code treats methods as signals
diff --git a/src/qml/types/qqmlconnections.cpp b/src/qml/types/qqmlconnections.cpp
index 1e801641e5..4c44bba43e 100644
--- a/src/qml/types/qqmlconnections.cpp
+++ b/src/qml/types/qqmlconnections.cpp
@@ -238,7 +238,8 @@ void QQmlConnectionsParser::verifyBindings(const QQmlRefPointer<QV4::ExecutableC
const QV4::CompiledData::Binding *binding = props.at(ii);
const QString &propName = compilationUnit->stringAt(binding->propertyNameIndex);
- if (!propName.startsWith(QLatin1String("on")) || (propName.length() < 3 || !propName.at(2).isUpper())) {
+ const bool thirdCharacterIsValid = (propName.length() >= 2) && (propName.at(2).isUpper() || propName.at(2) == '_');
+ if (!propName.startsWith(QLatin1String("on")) || !thirdCharacterIsValid) {
error(props.at(ii), QQmlConnections::tr("Cannot assign to non-existent property \"%1\"").arg(propName));
return;
}
diff --git a/tests/auto/qml/qqmlconnections/data/underscore.qml b/tests/auto/qml/qqmlconnections/data/underscore.qml
new file mode 100644
index 0000000000..0f73dc8f17
--- /dev/null
+++ b/tests/auto/qml/qqmlconnections/data/underscore.qml
@@ -0,0 +1,14 @@
+import QtQuick 2.12
+
+Item {
+ id: item
+ property bool success: false
+ property bool sanityCheck: false
+ property int __underscore_property: 0
+ on__Underscore_propertyChanged: item.sanityCheck = true
+
+ Connections {
+ target: item
+ on__Underscore_propertyChanged: item.success = true
+ }
+}
diff --git a/tests/auto/qml/qqmlconnections/tst_qqmlconnections.cpp b/tests/auto/qml/qqmlconnections/tst_qqmlconnections.cpp
index 07af519a3d..f144002875 100644
--- a/tests/auto/qml/qqmlconnections/tst_qqmlconnections.cpp
+++ b/tests/auto/qml/qqmlconnections/tst_qqmlconnections.cpp
@@ -77,6 +77,8 @@ private slots:
void noAcceleratedGlobalLookup_data() { prefixes(); }
void noAcceleratedGlobalLookup();
+ void bindToPropertyWithUnderscoreChangeHandler();
+
private:
QQmlEngine engine;
void prefixes();
@@ -474,6 +476,19 @@ void tst_qqmlconnections::noAcceleratedGlobalLookup()
QCOMPARE(val.toInt(), int(Proxy::EnumValue));
}
+void tst_qqmlconnections::bindToPropertyWithUnderscoreChangeHandler()
+{
+ QQmlEngine engine;
+ QQmlComponent component(&engine, testFileUrl("underscore.qml"));
+ QScopedPointer<QObject> root {component.create()};
+ QVERIFY(root);
+ QQmlProperty underscoreProperty(root.get(), "__underscore_property");
+ QVERIFY(underscoreProperty.isValid());
+ underscoreProperty.write(42);
+ QVERIFY(root->property("sanityCheck").toBool());
+ QVERIFY(root->property("success").toBool());
+}
+
QTEST_MAIN(tst_qqmlconnections)
#include "tst_qqmlconnections.moc"
diff --git a/tests/auto/qml/qqmlproperty/tst_qqmlproperty.cpp b/tests/auto/qml/qqmlproperty/tst_qqmlproperty.cpp
index a15c00ad62..864a47e998 100644
--- a/tests/auto/qml/qqmlproperty/tst_qqmlproperty.cpp
+++ b/tests/auto/qml/qqmlproperty/tst_qqmlproperty.cpp
@@ -158,6 +158,8 @@ private slots:
void copy();
void nestedQQmlPropertyMap();
+
+ void underscorePropertyChangeHandler();
private:
QQmlEngine engine;
};
@@ -2230,6 +2232,24 @@ void tst_qqmlproperty::nestedQQmlPropertyMap()
QCOMPARE(success.read().toString(), QLatin1String("success"));
}
+void tst_qqmlproperty::underscorePropertyChangeHandler()
+{
+ QQmlEngine engine;
+ QQmlComponent component(&engine);
+ component.setData(R"(
+ import QtQuick 2.12
+
+ Item {
+ property int __withUnderScore
+ }
+ )", QUrl::fromLocalFile("."));
+ QScopedPointer<QObject> root { component.create() };
+ QVERIFY(root);
+ QQmlProperty changeHandler(root.get(), "on__WithUnderScoreChanged");
+ QVERIFY(changeHandler.isValid());
+ QVERIFY(changeHandler.isSignalProperty());
+}
+
QTEST_MAIN(tst_qqmlproperty)
#include "tst_qqmlproperty.moc"