summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLiang Qi <liang.qi@qt.io>2020-03-09 11:45:59 +0100
committerLiang Qi <liang.qi@qt.io>2020-03-09 11:45:59 +0100
commit062075e1463b46ea4db76669f052d10ccfa2a0c9 (patch)
tree6a7ca3c2eee2ab90ef74b9f4934c91f3b3557f61
parent09838389f3b9eaf67ad2e0b02a85a62a63fbfc38 (diff)
parent14daacff9654980381a1d0b7b09d0b25f6c9dbb2 (diff)
Merge remote-tracking branch 'origin/5.14' into 5.15
Conflicts: tests/auto/qml/usertypes/tst_usertypes.cpp Change-Id: I486c04220940f8fda0c308d7011c2afac6fd871d
-rw-r--r--src/remoteobjects/qremoteobjectreplica.cpp26
-rw-r--r--tests/auto/integration/tst_integration.cpp26
-rw-r--r--tests/auto/modelreplica/tst_modelreplicatest.cpp4
-rw-r--r--tests/auto/qml/usertypes/data/extraprop2.qml11
-rw-r--r--tests/auto/qml/usertypes/data/twoReplicas.qml29
-rw-r--r--tests/auto/qml/usertypes/tst_usertypes.cpp38
6 files changed, 129 insertions, 5 deletions
diff --git a/src/remoteobjects/qremoteobjectreplica.cpp b/src/remoteobjects/qremoteobjectreplica.cpp
index e619e83..04d9ca5 100644
--- a/src/remoteobjects/qremoteobjectreplica.cpp
+++ b/src/remoteobjects/qremoteobjectreplica.cpp
@@ -209,7 +209,7 @@ void QConnectedReplicaImplementation::initialize(QVariantList &values)
qCDebug(QT_REMOTEOBJECT) << "initialize()" << m_propertyStorage.size();
const int nParam = values.size();
QVarLengthArray<int> changedProperties(nParam);
- const int offset = m_metaObject->propertyOffset();
+ const int offset = m_propertyOffset;
for (int i = 0; i < nParam; ++i) {
qCDebug(QT_REMOTEOBJECT) << " in loop" << i << m_propertyStorage.size();
changedProperties[i] = -1;
@@ -556,9 +556,29 @@ void QRemoteObjectReplicaImplementation::configurePrivate(QRemoteObjectReplica *
void QConnectedReplicaImplementation::configurePrivate(QRemoteObjectReplica *rep)
{
- if (m_metaObject)
+ if (m_metaObject) {
+ // see QRemoteObjectReplicaImplementation::configurePrivate
+ const bool firstReplicaInstance = (m_methodOffset == 0);
+
QRemoteObjectReplicaImplementation::configurePrivate(rep);
- else
+
+ // ensure that notify signals are emitted for the new replica, when
+ // we are initializing an nth replica of the same type
+ if (!firstReplicaInstance) {
+ const int offset = m_propertyOffset;
+ const int nParam = m_propertyStorage.count();
+ void *args[] = {nullptr, nullptr};
+ for (int i = 0; i < nParam; ++i) {
+ const int notifyIndex = m_metaObject->property(i+offset).notifySignalIndex();
+ if (notifyIndex < 0)
+ continue;
+ qCDebug(QT_REMOTEOBJECT) << " Before activate" << notifyIndex << m_metaObject->property(i+offset).name();
+ args[1] = m_propertyStorage[i].data();
+ // NOTE: this over-emits (assumes all values have changed)
+ QMetaObject::activate(rep, rep->metaObject(), notifyIndex - m_signalOffset, args);
+ }
+ }
+ } else
m_parentsNeedingConnect.append(rep);
}
diff --git a/tests/auto/integration/tst_integration.cpp b/tests/auto/integration/tst_integration.cpp
index 0718219..4f65243 100644
--- a/tests/auto/integration/tst_integration.cpp
+++ b/tests/auto/integration/tst_integration.cpp
@@ -1062,6 +1062,32 @@ private slots:
QCOMPARE(engine_r2->rpm(), e.rpm());
}
+ // verify that our second replica emits "Changed" signals when initialized
+ void doubleReplicaTest2()
+ {
+ setupHost();
+ Engine e;
+ host->enableRemoting(&e);
+ e.setRpm(3412);
+
+ setupClient();
+
+ const QScopedPointer<EngineReplica> engine_r1(client->acquire< EngineReplica >());
+ QSignalSpy spy_r1(engine_r1.data(), SIGNAL(rpmChanged(int)));
+ engine_r1->waitForSource();
+ QCOMPARE(engine_r1->rpm(), e.rpm());
+ QCOMPARE(spy_r1.count(), 1);
+
+ // NOTE: A second replica will have initialized and notify signals emitted as part of acquire,
+ // which leads to different semantics for first and second replicas. Specifically, there is no
+ // way to hook in to initialized and the initial notify signals. We should consider changing this.
+ const QScopedPointer<EngineReplica> engine_r2(client->acquire< EngineReplica >());
+// QSignalSpy spy_r2(engine_r2.data(), SIGNAL(rpmChanged(int)));
+// engine_r2->waitForSource();
+ QCOMPARE(engine_r2->rpm(), e.rpm());
+// QCOMPARE(spy_r2.count(), 1);
+ }
+
void twoReplicaTest() {
setupHost();
Engine e;
diff --git a/tests/auto/modelreplica/tst_modelreplicatest.cpp b/tests/auto/modelreplica/tst_modelreplicatest.cpp
index 1e3f5eb..40b622e 100644
--- a/tests/auto/modelreplica/tst_modelreplicatest.cpp
+++ b/tests/auto/modelreplica/tst_modelreplicatest.cpp
@@ -67,7 +67,7 @@ void ModelreplicaTest::basicFunctions()
QRemoteObjectNode client(QUrl("tcp://localhost:5555"));
const QScopedPointer<MediaReplica> replica(client.acquire<MediaReplica>());
QSignalSpy tracksSpy(replica->tracks(), &QAbstractItemModelReplica::initialized);
- QVERIFY(replica->waitForSource(100));
+ QVERIFY(replica->waitForSource(300));
QVERIFY(tracksSpy.wait());
// Rep file only uses display role
QCOMPARE(QVector<int>{Qt::DisplayRole}, replica->tracks()->availableRoles());
@@ -96,7 +96,7 @@ void ModelreplicaTest::nullModel()
QRemoteObjectNode client(QUrl("tcp://localhost:5555"));
const QScopedPointer<MediaReplica> replica(client.acquire<MediaReplica>());
- QVERIFY(replica->waitForSource(100));
+ QVERIFY(replica->waitForSource(300));
auto model = new QStringListModel(this);
model->setStringList(QStringList() << "Track1" << "Track2" << "Track3");
diff --git a/tests/auto/qml/usertypes/data/extraprop2.qml b/tests/auto/qml/usertypes/data/extraprop2.qml
new file mode 100644
index 0000000..35d9d51
--- /dev/null
+++ b/tests/auto/qml/usertypes/data/extraprop2.qml
@@ -0,0 +1,11 @@
+import QtQuick 2.0
+import QtRemoteObjects 5.12
+import usertypes 1.0
+
+SimpleClockReplica {
+ property string result: hour // test that the existence of this property doesn't cause issues
+
+ node: Node {
+ registryUrl: "local:test2"
+ }
+}
diff --git a/tests/auto/qml/usertypes/data/twoReplicas.qml b/tests/auto/qml/usertypes/data/twoReplicas.qml
new file mode 100644
index 0000000..1516465
--- /dev/null
+++ b/tests/auto/qml/usertypes/data/twoReplicas.qml
@@ -0,0 +1,29 @@
+import QtQuick 2.0
+import QtRemoteObjects 5.12
+import usertypes 1.0
+
+Item {
+ property int result: replica.hour
+ property int result2: replica2.hour
+
+ Node {
+ id: sharedNode
+ registryUrl: "local:testTwoReplicas"
+ }
+
+ SimpleClockReplica {
+ id: replica
+ node: sharedNode
+ }
+
+ SimpleClockReplica {
+ id: replica2
+ }
+
+ Timer {
+ running: true
+ interval: 200
+ onTriggered: replica2.node = sharedNode
+ }
+}
+
diff --git a/tests/auto/qml/usertypes/tst_usertypes.cpp b/tests/auto/qml/usertypes/tst_usertypes.cpp
index e5a8b6f..21fac1a 100644
--- a/tests/auto/qml/usertypes/tst_usertypes.cpp
+++ b/tests/auto/qml/usertypes/tst_usertypes.cpp
@@ -56,6 +56,7 @@ public:
private Q_SLOTS:
void extraPropertyInQml();
+ void extraPropertyInQml2();
void extraPropertyInQmlComplex();
void modelInQml();
void subObjectInQml();
@@ -63,6 +64,7 @@ private Q_SLOTS:
void complexInQml();
void watcherInQml();
void hostInQml();
+ void twoReplicas();
};
tst_usertypes::tst_usertypes()
@@ -86,6 +88,24 @@ void tst_usertypes::extraPropertyInQml()
QTRY_COMPARE_WITH_TIMEOUT(obj->property("result").value<int>(), 10, 300);
}
+void tst_usertypes::extraPropertyInQml2()
+{
+ qmlRegisterType<SimpleClockReplica>("usertypes", 1, 0, "SimpleClockReplica");
+
+ QRemoteObjectRegistryHost host(QUrl("local:test2"));
+ SimpleClockSimpleSource clock;
+ clock.setHour(10);
+ host.enableRemoting(&clock);
+
+ QQmlEngine e;
+ QQmlComponent c(&e, SRCDIR "data/extraprop2.qml");
+ QObject *obj = c.create();
+ QVERIFY(obj);
+
+ QTRY_COMPARE_WITH_TIMEOUT(obj->property("hour").value<int>(), 10, 300);
+ QCOMPARE(obj->property("result").value<int>(), 10);
+}
+
void tst_usertypes::extraPropertyInQmlComplex()
{
QRemoteObjectRegistryHost host(QUrl("local:testExtraComplex"));
@@ -251,6 +271,24 @@ void tst_usertypes::hostInQml()
QTRY_COMPARE_WITH_TIMEOUT(replica->state(), QRemoteObjectReplica::Valid, 300);
}
+void tst_usertypes::twoReplicas()
+{
+ qmlRegisterType<SimpleClockReplica>("usertypes", 1, 0, "SimpleClockReplica");
+
+ QRemoteObjectRegistryHost host(QUrl("local:testTwoReplicas"));
+ SimpleClockSimpleSource clock;
+ clock.setHour(7);
+ host.enableRemoting(&clock);
+
+ QQmlEngine e;
+ QQmlComponent c(&e, SRCDIR "data/twoReplicas.qml");
+ QObject *obj = c.create();
+ QVERIFY(obj);
+
+ QTRY_COMPARE_WITH_TIMEOUT(obj->property("result").value<int>(), 7, 300);
+ QTRY_COMPARE_WITH_TIMEOUT(obj->property("result2").value<int>(), 7, 500);
+}
+
QTEST_MAIN(tst_usertypes)
#include "tst_usertypes.moc"