summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorØystein Heskestad <oystein.heskestad@qt.io>2023-07-17 18:12:59 +0200
committerQt Cherry-pick Bot <cherrypick_bot@qt-project.org>2023-08-16 11:12:57 +0000
commit39461a42d284121345c42301d2d0d3ce187aec15 (patch)
tree5f6b01f0df605bc883f874a14364b259489c9d98
parentce9f2c0d86d2582abbc3cc20c99df3e1a9076c9b (diff)
Update snippets to match the simpleswitch examples they are taken from
This is a clean up of the snippets before the simpleswitch examples are removed. Task-number: QTBUG-112850 Change-Id: Ib58676fe8ad95ce52a108cd3a4d986534e2eb1b5 Reviewed-by: Dennis Oberst <dennis.oberst@qt.io> Reviewed-by: Edward Welbourne <edward.welbourne@qt.io> (cherry picked from commit 82fd6b3d12ff4d5d4449191b317e2d69fbadc4a3) Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
-rw-r--r--src/remoteobjects/doc/snippets/doc_src_simpleswitch.cpp83
1 files changed, 42 insertions, 41 deletions
diff --git a/src/remoteobjects/doc/snippets/doc_src_simpleswitch.cpp b/src/remoteobjects/doc/snippets/doc_src_simpleswitch.cpp
index 30c6ba7..2687c62 100644
--- a/src/remoteobjects/doc/snippets/doc_src_simpleswitch.cpp
+++ b/src/remoteobjects/doc/snippets/doc_src_simpleswitch.cpp
@@ -29,7 +29,7 @@ class SimpleSwitch : public SimpleSwitchSimpleSource
public:
SimpleSwitch(QObject *parent = nullptr);
~SimpleSwitch();
- virtual void server_slot(bool clientState);
+ void server_slot(bool clientState) override;
public Q_SLOTS:
void timeout_slot();
private:
@@ -75,7 +75,7 @@ void SimpleSwitch::timeout_slot()
//! [simpleSwitch_serversource_example1]
//! [simpleSwitch_serverhostnode_example1]
-QRemoteObjectHost srcNode(QUrl(QStringLiteral("local:switch")));
+QRemoteObjectHost srcNode(QUrl(QStringLiteral("local:replica")));
//! [simpleSwitch_serverhostnode_example1]
//! [simpleSwitch_enableremoting_example1]
@@ -93,7 +93,8 @@ int main(int argc, char *argv[])
SimpleSwitch srcSwitch; // create simple switch
- QRemoteObjectHost srcNode(QUrl(QStringLiteral("local:switch"))); // create host node without Registry
+ // Create host node without Registry:
+ QRemoteObjectHost srcNode(QUrl(QStringLiteral("local:replica")));
srcNode.enableRemoting(&srcSwitch); // enable remoting/sharing
return a.exec();
@@ -106,8 +107,8 @@ REPC_REPLICA = simpleswitch.rep
//! [simpleSwitch_clientremotenode_example1]
QRemoteObjectNode repNode; // create remote object node
-repNode.connectToNode(QUrl(QStringLiteral("local:switch"))); // connect with remote host node
- //! [simpleSwitch_clientremotenode_example1]
+repNode.connectToNode(QUrl(QStringLiteral("local:replica"))); // connect with remote host node
+//! [simpleSwitch_clientremotenode_example1]
//! [simpleSwitch_clientacquirereplica_example1]
QSharedPointer<SimpleSwitchReplica> ptr;
@@ -128,14 +129,14 @@ class Client : public QObject
Q_OBJECT
public:
Client(QSharedPointer<SimpleSwitchReplica> ptr);
- ~Client();
+ ~Client() override = default;
void initConnections();// Function to connect signals and slots of source and client
Q_SIGNALS:
void echoSwitchState(bool switchState);// this signal is connected with server_slot(..) on the source object and echoes back switch state received from source
public Q_SLOTS:
- void recSwitchState_slot(); // slot to receive source state
+ void recSwitchState_slot(bool); // slot to receive source state
private:
bool clientSwitchState; // holds received server switch state
QSharedPointer<SimpleSwitchReplica> reptr;// holds reference to replica
@@ -152,14 +153,10 @@ private:
Client::Client(QSharedPointer<SimpleSwitchReplica> ptr) :
QObject(nullptr),reptr(ptr)
{
+ // Connect signal for replica initialized with initialization slot.
initConnections();
- //We can connect to SimpleSwitchReplica Signals/Slots
- //directly because our Replica was generated by repc.
-}
-
-//destructor
-Client::~Client()
-{
+ // We can connect to SimpleSwitchReplica Signals/Slots
+ // directly because our Replica was generated by repc.
}
void Client::initConnections()
@@ -192,7 +189,7 @@ int main(int argc, char *argv[])
QSharedPointer<SimpleSwitchReplica> ptr; // shared pointer to hold source replica
QRemoteObjectNode repNode; // create remote object node
- repNode.connectToNode(QUrl(QStringLiteral("local:switch"))); // connect with remote host node
+ repNode.connectToNode(QUrl(QStringLiteral("local:replica"))); // connect with remote host node
ptr.reset(repNode.acquire<SimpleSwitchReplica>()); // acquire replica of source from host node
@@ -204,7 +201,7 @@ int main(int argc, char *argv[])
//! [simpleSwitch_dynamicclientnode_example2]
QRemoteObjectNode repNode; // create remote object node
-repNode.connectToNode(QUrl(QStringLiteral("local:switch"))); // connect with remote host node
+repNode.connectToNode(QUrl(QStringLiteral("local:replica"))); // connect with remote host node
//! [simpleSwitch_dynamicclientnode_example2]
//! [simpleSwitch_dynamicclientacquirereplica_example2]
@@ -227,14 +224,14 @@ class DynamicClient : public QObject
Q_OBJECT
public:
DynamicClient(QSharedPointer<QRemoteObjectDynamicReplica> ptr);
- ~DynamicClient();
+ ~DynamicClient() override = default;
Q_SIGNALS:
void echoSwitchState(bool switchState);// this signal is connected with server_slot(..) slot of source object and echoes back switch state received from source
public Q_SLOTS:
- void recSwitchState_slot(); // Slot to receive source state
- void initConnection_slot(); //Slot to connect signals/slot on replica initialization
+ void recSwitchState_slot(bool); // Slot to receive source state
+ void initConnection_slot(); // Slot to connect signals/slot on replica initialization
private:
bool clientSwitchState; // holds received server switch state
@@ -248,35 +245,33 @@ private:
#include "dynamicclient.h"
// constructor
-DynamicClient::DynamicClient(QSharedPointer<QRemoteObjectDynamicReplica> ptr) :
- QObject(nullptr), reptr(ptr)
+DynamicClient::DynamicClient(QSharedPointer<QRemoteObjectDynamicReplica> ptr)
+ : QObject(nullptr), clientSwitchState(false), reptr(ptr)
{
-
//connect signal for replica valid changed with signal slot initialization
QObject::connect(reptr.data(), &QRemoteObjectDynamicReplica::initialized, this,
&DynamicClient::initConnection_slot);
}
-//destructor
-DynamicClient::~DynamicClient()
-{
-}
-
// Function to initialize connections between slots and signals
void DynamicClient::initConnection_slot()
{
-
- // connect source replica signal currStateChanged() with client's recSwitchState() slot to receive source's current state
- QObject::connect(reptr.data(), SIGNAL(currStateChanged()), this, SLOT(recSwitchState_slot()));
- // connect client's echoSwitchState(..) signal with replica's server_slot(..) to echo back received state
- QObject::connect(this, SIGNAL(echoSwitchState(bool)),reptr.data(), SLOT(server_slot(bool)));
+ // Connect source replica signal currStateChanged() with client's
+ // recSwitchState() slot to receive source's current state:
+ QObject::connect(reptr.data(), SIGNAL(currStateChanged(bool)), this,
+ SLOT(recSwitchState_slot(bool)));
+ // Connect client's echoSwitchState(..) signal with replica's
+ // server_slot(..) to echo back received state:
+ QObject::connect(this, SIGNAL(echoSwitchState(bool)), reptr.data(), SLOT(server_slot(bool)));
}
-void DynamicClient::recSwitchState_slot()
+void DynamicClient::recSwitchState_slot(bool value)
{
- clientSwitchState = reptr->property("currState").toBool(); // use replica property to get currState from source
- qDebug() << "Received source state " << clientSwitchState;
- Q_EMIT echoSwitchState(clientSwitchState); // Emit signal to echo received state back to server
+ // Use replica property to get "currState" from source:
+ clientSwitchState = reptr->property("currState").toBool();
+ qDebug() << "Received source state " << value << clientSwitchState;
+ // Emit signal to echo received state back to server:
+ Q_EMIT echoSwitchState(clientSwitchState);
}
//! [simpleSwitch_dynamicclientcpp_example2]
@@ -293,11 +288,13 @@ int main(int argc, char *argv[])
QSharedPointer<QRemoteObjectDynamicReplica> ptr; // shared pointer to hold replica
QRemoteObjectNode repNode;
- repNode.connectToNode(QUrl(QStringLiteral("local:switch")));
+ repNode.connectToNode(QUrl(QStringLiteral("local:replica")));
ptr.reset(repNode.acquireDynamic("SimpleSwitch")); // acquire replica of source from host node
DynamicClient rswitch(ptr); // create client switch object and pass replica reference to it
+
+ return a.exec();
}
//! [simpleSwitch_dynamicclientmaincpp_example2]
@@ -311,10 +308,14 @@ int main(int argc, char *argv[])
SimpleSwitch srcSwitch; // create SimpleSwitch
- QRemoteObjectRegistryHost regNode(QUrl(QStringLiteral("local:registry"))); // create node that hosts registry
- QRemoteObjectHost srcNode(QUrl(QStringLiteral("local:switch")), QUrl(QStringLiteral("local:registry"))); // create node that will host source and connect to registry
- //Note, you can add srcSwitch directly to regNode if desired.
- //We use two Nodes here, as the regNode could easily be in a third process.
+ // Create node that hosts registry:
+ QRemoteObjectRegistryHost regNode(QUrl(QStringLiteral("local:registry")));
+
+ // Create node that will host source and connect to registry:
+ QRemoteObjectHost srcNode(QUrl(QStringLiteral("local:replica")),
+ QUrl(QStringLiteral("local:registry")));
+ // Note, you can add srcSwitch directly to regNode if desired.
+ // We use two Nodes here, as the regNode could easily be in a third process.
srcNode.enableRemoting(&srcSwitch); // enable remoting of source object