diff options
author | Øystein Heskestad <oystein.heskestad@qt.io> | 2023-09-21 15:21:16 +0200 |
---|---|---|
committer | Øystein Heskestad <oystein.heskestad@qt.io> | 2023-09-22 15:17:26 +0200 |
commit | cc349f6ee3ba05e9f3c53cd96b7d7d5565227cb4 (patch) | |
tree | 6a6a4284940b29eae154799b1fd854719757a1ca /examples | |
parent | db9f186d4f14ec9e9834529dcc04b7d8b3533e19 (diff) |
Move some simpleswitch examples to tests/manual/examples
There have already been created snippets based on these small examples
used in the remote objects documentation.
Task-number: QTBUG-112850
Pick-to: 6.6 6.5
Change-Id: Ib495eea8f8416831229961acd8f873b943da317d
Reviewed-by: Brett Stottlemyer <bstottle@ford.com>
Diffstat (limited to 'examples')
18 files changed, 1 insertions, 479 deletions
diff --git a/examples/remoteobjects/simpleswitch/CMakeLists.txt b/examples/remoteobjects/simpleswitch/CMakeLists.txt index 5e53132..23f245a 100644 --- a/examples/remoteobjects/simpleswitch/CMakeLists.txt +++ b/examples/remoteobjects/simpleswitch/CMakeLists.txt @@ -3,8 +3,5 @@ if (NOT ANDROID) qt_internal_add_example(directconnectclient) - qt_internal_add_example(directconnectdynamicclient) qt_internal_add_example(directconnectserver) - qt_internal_add_example(registryconnectedclient) - qt_internal_add_example(registryconnectedserver) endif() diff --git a/examples/remoteobjects/simpleswitch/directconnectdynamicclient/CMakeLists.txt b/examples/remoteobjects/simpleswitch/directconnectdynamicclient/CMakeLists.txt deleted file mode 100644 index 828a4fe..0000000 --- a/examples/remoteobjects/simpleswitch/directconnectdynamicclient/CMakeLists.txt +++ /dev/null @@ -1,40 +0,0 @@ -# Copyright (C) 2022 The Qt Company Ltd. -# SPDX-License-Identifier: BSD-3-Clause - -cmake_minimum_required(VERSION 3.16) -project(directconnectdynamicclient LANGUAGES CXX) - -if (ANDROID) - message(FATAL_ERROR "This project cannot be built on Android.") -endif() - -set(CMAKE_AUTOMOC ON) - -if(NOT DEFINED INSTALL_EXAMPLESDIR) - set(INSTALL_EXAMPLESDIR "examples") -endif() - -set(INSTALL_EXAMPLEDIR "${INSTALL_EXAMPLESDIR}/remoteobjects/simpleswitch/directconnectdynamicclient") - -find_package(Qt6 REQUIRED COMPONENTS Core RemoteObjects) - -qt_add_executable(directconnectdynamicclient - dynamicclient.cpp dynamicclient.h - main.cpp -) - -set_target_properties(directconnectdynamicclient PROPERTIES - WIN32_EXECUTABLE FALSE - MACOSX_BUNDLE FALSE -) - -target_link_libraries(directconnectdynamicclient PUBLIC - Qt::Core - Qt::RemoteObjects -) - -install(TARGETS directconnectdynamicclient - RUNTIME DESTINATION "${INSTALL_EXAMPLEDIR}" - BUNDLE DESTINATION "${INSTALL_EXAMPLEDIR}" - LIBRARY DESTINATION "${INSTALL_EXAMPLEDIR}" -) diff --git a/examples/remoteobjects/simpleswitch/directconnectdynamicclient/directconnectdynamicclient.pro b/examples/remoteobjects/simpleswitch/directconnectdynamicclient/directconnectdynamicclient.pro deleted file mode 100644 index 8b907de..0000000 --- a/examples/remoteobjects/simpleswitch/directconnectdynamicclient/directconnectdynamicclient.pro +++ /dev/null @@ -1,18 +0,0 @@ -QT += remoteobjects core - -QT -= gui - -TARGET = directconnectdynamicclient -CONFIG += console -CONFIG -= app_bundle - -TEMPLATE = app - -target.path = $$[QT_INSTALL_EXAMPLES]/remoteobjects/simpleswitch/directconnectdynamicclient -INSTALLS += target - -SOURCES += main.cpp \ - dynamicclient.cpp - -HEADERS += \ - dynamicclient.h diff --git a/examples/remoteobjects/simpleswitch/directconnectdynamicclient/dynamicclient.cpp b/examples/remoteobjects/simpleswitch/directconnectdynamicclient/dynamicclient.cpp deleted file mode 100644 index 6f88fa6..0000000 --- a/examples/remoteobjects/simpleswitch/directconnectdynamicclient/dynamicclient.cpp +++ /dev/null @@ -1,39 +0,0 @@ -// Copyright (C) 2017 Ford Motor Company -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause - -#include "dynamicclient.h" - #include <QMetaMethod> - -// constructor -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(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(bool value) -{ - clientSwitchState = reptr->property("currState").toBool(); // use replica property to get "currState" from source - qDebug() << "Received source state " << value << clientSwitchState; - Q_EMIT echoSwitchState(clientSwitchState); // Emit signal to echo received state back to server -} - diff --git a/examples/remoteobjects/simpleswitch/directconnectdynamicclient/dynamicclient.h b/examples/remoteobjects/simpleswitch/directconnectdynamicclient/dynamicclient.h deleted file mode 100644 index 18a0548..0000000 --- a/examples/remoteobjects/simpleswitch/directconnectdynamicclient/dynamicclient.h +++ /dev/null @@ -1,33 +0,0 @@ -// Copyright (C) 2017 Ford Motor Company -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause - -#ifndef _DYNAMICCLIENT_H -#define _DYNAMICCLIENT_H - -#include <QObject> -#include <QSharedPointer> - -#include <QRemoteObjectNode> -#include <qremoteobjectdynamicreplica.h> - -class DynamicClient : public QObject -{ - Q_OBJECT -public: - DynamicClient(QSharedPointer<QRemoteObjectDynamicReplica> ptr); - ~DynamicClient() override; - -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(bool); // slot to receive source state - void initConnection_slot(); - -private: - bool clientSwitchState; // holds received server switch state - QSharedPointer<QRemoteObjectDynamicReplica> reptr;// holds reference to replica - }; - -#endif - diff --git a/examples/remoteobjects/simpleswitch/directconnectdynamicclient/main.cpp b/examples/remoteobjects/simpleswitch/directconnectdynamicclient/main.cpp deleted file mode 100644 index 50be9ab..0000000 --- a/examples/remoteobjects/simpleswitch/directconnectdynamicclient/main.cpp +++ /dev/null @@ -1,22 +0,0 @@ -// Copyright (C) 2017 Ford Motor Company -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause - -#include <QCoreApplication> - -#include "dynamicclient.h" - -int main(int argc, char *argv[]) -{ - QCoreApplication a(argc, argv); - - QSharedPointer<QRemoteObjectDynamicReplica> ptr; // shared pointer to hold replica - - QRemoteObjectNode repNode; // create remote object node - repNode.connectToNode(QUrl(QStringLiteral("local:replica"))); // connect with remote host node - - 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(); -} diff --git a/examples/remoteobjects/simpleswitch/registryconnectedclient/CMakeLists.txt b/examples/remoteobjects/simpleswitch/registryconnectedclient/CMakeLists.txt deleted file mode 100644 index 17c4609..0000000 --- a/examples/remoteobjects/simpleswitch/registryconnectedclient/CMakeLists.txt +++ /dev/null @@ -1,40 +0,0 @@ -# Copyright (C) 2022 The Qt Company Ltd. -# SPDX-License-Identifier: BSD-3-Clause - -cmake_minimum_required(VERSION 3.16) -project(registryconnectedclient LANGUAGES CXX) - -if (ANDROID) - message(FATAL_ERROR "This project cannot be built on Android.") -endif() - -set(CMAKE_AUTOMOC ON) - -if(NOT DEFINED INSTALL_EXAMPLESDIR) - set(INSTALL_EXAMPLESDIR "examples") -endif() - -set(INSTALL_EXAMPLEDIR "${INSTALL_EXAMPLESDIR}/remoteobjects/simpleswitch/registryconnectedclient") - -find_package(Qt6 REQUIRED COMPONENTS Core RemoteObjects) - -qt_add_executable(registryconnectedclient - dynamicclient.cpp dynamicclient.h - main.cpp -) - -set_target_properties(registryconnectedclient PROPERTIES - WIN32_EXECUTABLE FALSE - MACOSX_BUNDLE FALSE -) - -target_link_libraries(registryconnectedclient PUBLIC - Qt::Core - Qt::RemoteObjects -) - -install(TARGETS registryconnectedclient - RUNTIME DESTINATION "${INSTALL_EXAMPLEDIR}" - BUNDLE DESTINATION "${INSTALL_EXAMPLEDIR}" - LIBRARY DESTINATION "${INSTALL_EXAMPLEDIR}" -) diff --git a/examples/remoteobjects/simpleswitch/registryconnectedclient/dynamicclient.cpp b/examples/remoteobjects/simpleswitch/registryconnectedclient/dynamicclient.cpp deleted file mode 100644 index 6f88fa6..0000000 --- a/examples/remoteobjects/simpleswitch/registryconnectedclient/dynamicclient.cpp +++ /dev/null @@ -1,39 +0,0 @@ -// Copyright (C) 2017 Ford Motor Company -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause - -#include "dynamicclient.h" - #include <QMetaMethod> - -// constructor -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(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(bool value) -{ - clientSwitchState = reptr->property("currState").toBool(); // use replica property to get "currState" from source - qDebug() << "Received source state " << value << clientSwitchState; - Q_EMIT echoSwitchState(clientSwitchState); // Emit signal to echo received state back to server -} - diff --git a/examples/remoteobjects/simpleswitch/registryconnectedclient/dynamicclient.h b/examples/remoteobjects/simpleswitch/registryconnectedclient/dynamicclient.h deleted file mode 100644 index 18a0548..0000000 --- a/examples/remoteobjects/simpleswitch/registryconnectedclient/dynamicclient.h +++ /dev/null @@ -1,33 +0,0 @@ -// Copyright (C) 2017 Ford Motor Company -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause - -#ifndef _DYNAMICCLIENT_H -#define _DYNAMICCLIENT_H - -#include <QObject> -#include <QSharedPointer> - -#include <QRemoteObjectNode> -#include <qremoteobjectdynamicreplica.h> - -class DynamicClient : public QObject -{ - Q_OBJECT -public: - DynamicClient(QSharedPointer<QRemoteObjectDynamicReplica> ptr); - ~DynamicClient() override; - -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(bool); // slot to receive source state - void initConnection_slot(); - -private: - bool clientSwitchState; // holds received server switch state - QSharedPointer<QRemoteObjectDynamicReplica> reptr;// holds reference to replica - }; - -#endif - diff --git a/examples/remoteobjects/simpleswitch/registryconnectedclient/main.cpp b/examples/remoteobjects/simpleswitch/registryconnectedclient/main.cpp deleted file mode 100644 index 9ed41fa..0000000 --- a/examples/remoteobjects/simpleswitch/registryconnectedclient/main.cpp +++ /dev/null @@ -1,20 +0,0 @@ -// Copyright (C) 2017 Ford Motor Company -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause - -#include <QCoreApplication> -#include "dynamicclient.h" - -int main(int argc, char *argv[]) -{ - QCoreApplication a(argc, argv); - - QSharedPointer<QRemoteObjectDynamicReplica> ptr; // shared pointer to hold replica - - QRemoteObjectNode repNode(QUrl(QStringLiteral("local:registry"))); - - 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(); -} diff --git a/examples/remoteobjects/simpleswitch/registryconnectedclient/registryconnectedclient.pro b/examples/remoteobjects/simpleswitch/registryconnectedclient/registryconnectedclient.pro deleted file mode 100644 index 02aa54c..0000000 --- a/examples/remoteobjects/simpleswitch/registryconnectedclient/registryconnectedclient.pro +++ /dev/null @@ -1,24 +0,0 @@ -#------------------------------------------------- -# -# Project created by QtCreator 2015-02-13T15:22:50 -# -#------------------------------------------------- - -QT += remoteobjects core - -QT -= gui - -TARGET = registryconnectedclient -CONFIG += console -CONFIG -= app_bundle - -TEMPLATE = app - -target.path = $$[QT_INSTALL_EXAMPLES]/remoteobjects/simpleswitch/registryconnectedclient -INSTALLS += target - -SOURCES += main.cpp \ - dynamicclient.cpp - -HEADERS += \ - dynamicclient.h diff --git a/examples/remoteobjects/simpleswitch/registryconnectedserver/CMakeLists.txt b/examples/remoteobjects/simpleswitch/registryconnectedserver/CMakeLists.txt deleted file mode 100644 index 5239890..0000000 --- a/examples/remoteobjects/simpleswitch/registryconnectedserver/CMakeLists.txt +++ /dev/null @@ -1,45 +0,0 @@ -# Copyright (C) 2022 The Qt Company Ltd. -# SPDX-License-Identifier: BSD-3-Clause - -cmake_minimum_required(VERSION 3.16) -project(registryconnectedserver LANGUAGES CXX) - -if (ANDROID) - message(FATAL_ERROR "This project cannot be built on Android.") -endif() - -set(CMAKE_INCLUDE_CURRENT_DIR ON) -set(CMAKE_AUTOMOC ON) - -if(NOT DEFINED INSTALL_EXAMPLESDIR) - set(INSTALL_EXAMPLESDIR "examples") -endif() - -set(INSTALL_EXAMPLEDIR "${INSTALL_EXAMPLESDIR}/remoteobjects/simpleswitch/registryconnectedserver") - -find_package(Qt6 REQUIRED COMPONENTS Core RemoteObjects) - -qt_add_executable(registryconnectedserver - main.cpp - simpleswitch.cpp simpleswitch.h -) - -set_target_properties(registryconnectedserver PROPERTIES - WIN32_EXECUTABLE FALSE - MACOSX_BUNDLE FALSE -) - -target_link_libraries(registryconnectedserver PUBLIC - Qt::Core - Qt::RemoteObjects -) - -qt6_add_repc_sources(registryconnectedserver - simpleswitch.rep -) - -install(TARGETS registryconnectedserver - RUNTIME DESTINATION "${INSTALL_EXAMPLEDIR}" - BUNDLE DESTINATION "${INSTALL_EXAMPLEDIR}" - LIBRARY DESTINATION "${INSTALL_EXAMPLEDIR}" -) diff --git a/examples/remoteobjects/simpleswitch/registryconnectedserver/main.cpp b/examples/remoteobjects/simpleswitch/registryconnectedserver/main.cpp deleted file mode 100644 index 61480e4..0000000 --- a/examples/remoteobjects/simpleswitch/registryconnectedserver/main.cpp +++ /dev/null @@ -1,23 +0,0 @@ -// Copyright (C) 2017 Ford Motor Company -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause - -#include <QCoreApplication> -#include "simpleswitch.h" - -int main(int argc, char *argv[]) -{ - QCoreApplication a(argc, argv); - - SimpleSwitch srcSwitch; // create simple switch - - QRemoteObjectRegistryHost regNode(QUrl(QStringLiteral("local:registry"))); // create node that hosts registy - QRemoteObjectHost srcNode(QUrl(QStringLiteral("local:replica")), 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. - - srcNode.enableRemoting(&srcSwitch); // enable remoting of source object - - return a.exec(); -} - diff --git a/examples/remoteobjects/simpleswitch/registryconnectedserver/registryconnectedserver.pro b/examples/remoteobjects/simpleswitch/registryconnectedserver/registryconnectedserver.pro deleted file mode 100644 index d00687f..0000000 --- a/examples/remoteobjects/simpleswitch/registryconnectedserver/registryconnectedserver.pro +++ /dev/null @@ -1,30 +0,0 @@ -#------------------------------------------------- -# -# Project created by QtCreator 2015-02-13T15:02:06 -# -#------------------------------------------------- - -QT += remoteobjects core - -QT -= gui - -TARGET = registryconnectedserver -CONFIG += console -CONFIG -= app_bundle - -REPC_SOURCE = simpleswitch.rep - - -TEMPLATE = app - -target.path = $$[QT_INSTALL_EXAMPLES]/remoteobjects/simpleswitch/registryconnectedserver -INSTALLS += target - -SOURCES += main.cpp \ - simpleswitch.cpp - -HEADERS += \ - simpleswitch.h - -DISTFILES += \ - simpleswitch.rep diff --git a/examples/remoteobjects/simpleswitch/registryconnectedserver/simpleswitch.cpp b/examples/remoteobjects/simpleswitch/registryconnectedserver/simpleswitch.cpp deleted file mode 100644 index 16fe6a3..0000000 --- a/examples/remoteobjects/simpleswitch/registryconnectedserver/simpleswitch.cpp +++ /dev/null @@ -1,36 +0,0 @@ -// Copyright (C) 2017 Ford Motor Company -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause - -#include "simpleswitch.h" - -// constructor -SimpleSwitch::SimpleSwitch(QObject *parent) : SimpleSwitchSimpleSource(parent) -{ - stateChangeTimer = new QTimer(this); // Initialize timer - QObject::connect(stateChangeTimer, &QTimer::timeout, this, &SimpleSwitch::timeout_slot); // connect timeout() signal from stateChangeTimer to timeout_slot() of simpleSwitch - stateChangeTimer->start(2000); // Start timer and set timout to 2 seconds - qDebug() << "Source Node Started"; -} - -//destructor -SimpleSwitch::~SimpleSwitch() -{ - stateChangeTimer->stop(); -} - -void SimpleSwitch::server_slot(bool clientState) -{ - qDebug() << "Replica state is " << clientState; // print switch state echoed back by client -} - -void SimpleSwitch::timeout_slot(void) -{ - // slot called on timer timeout - if (currState()) // check if current state is true, currState() is defined in repc generated rep_simpleswitch_source.h - setCurrState(false); // set state to false - else - setCurrState(true); // set state to true - qDebug() << "Source State is "<<currState(); - -} - diff --git a/examples/remoteobjects/simpleswitch/registryconnectedserver/simpleswitch.h b/examples/remoteobjects/simpleswitch/registryconnectedserver/simpleswitch.h deleted file mode 100644 index da63652..0000000 --- a/examples/remoteobjects/simpleswitch/registryconnectedserver/simpleswitch.h +++ /dev/null @@ -1,22 +0,0 @@ -// Copyright (C) 2017 Ford Motor Company -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause - -#ifndef SIMPLESWITCH_H -#define SIMPLESWITCH_H - -#include "rep_simpleswitch_source.h" - -class SimpleSwitch : public SimpleSwitchSimpleSource -{ - Q_OBJECT -public: - SimpleSwitch(QObject *parent = nullptr); - ~SimpleSwitch() override; - void server_slot(bool clientState) override; -public Q_SLOTS: - void timeout_slot(); -private: - QTimer *stateChangeTimer; -}; - -#endif diff --git a/examples/remoteobjects/simpleswitch/registryconnectedserver/simpleswitch.rep b/examples/remoteobjects/simpleswitch/registryconnectedserver/simpleswitch.rep deleted file mode 100644 index 4f7c9c7..0000000 --- a/examples/remoteobjects/simpleswitch/registryconnectedserver/simpleswitch.rep +++ /dev/null @@ -1,8 +0,0 @@ -#include <QtCore> - -class SimpleSwitch -{ - PROP(bool currState=false); - SLOT(void server_slot(bool clientState)); -}; - diff --git a/examples/remoteobjects/simpleswitch/simpleswitch.pro b/examples/remoteobjects/simpleswitch/simpleswitch.pro index 8b70a12..d829d76 100644 --- a/examples/remoteobjects/simpleswitch/simpleswitch.pro +++ b/examples/remoteobjects/simpleswitch/simpleswitch.pro @@ -2,7 +2,4 @@ TEMPLATE = subdirs SUBDIRS += \ directconnectclient \ - directconnectdynamicclient \ - directconnectserver \ - registryconnectedclient \ - registryconnectedserver + directconnectserver |