diff options
author | Øystein Heskestad <oystein.heskestad@qt.io> | 2023-06-28 18:45:22 +0200 |
---|---|---|
committer | Øystein Heskestad <oystein.heskestad@qt.io> | 2023-07-06 09:35:15 +0200 |
commit | 1e1807220c61861a4077ef35b553e7dd74d85d69 (patch) | |
tree | 8ab88cef91dcb2e5ed9b04ee7635502950b140e8 /examples | |
parent | c4317ff10cae425e47c3636351e749f007195f2f (diff) |
Revamp clientapp and remoteobjects_server examples
Merge clientapp and plugins into a single stand-alone example.
Add documentation of clientapp and remoteobjects_server.
Task-number: QTBUG-112850
Pick-to: 6.6 6.5
Change-Id: I03340d3208fac7448f7de5d7720a61d2eeaf5a0a
Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io>
Diffstat (limited to 'examples')
30 files changed, 258 insertions, 287 deletions
diff --git a/examples/remoteobjects/CMakeLists.txt b/examples/remoteobjects/CMakeLists.txt index 5493be8..0e34de2 100644 --- a/examples/remoteobjects/CMakeLists.txt +++ b/examples/remoteobjects/CMakeLists.txt @@ -17,6 +17,5 @@ if(QT_FEATURE_ssl) add_subdirectory(ssl) endif() if(TARGET Qt::Quick) - qt_internal_add_example(plugins) qt_internal_add_example(clientapp) endif() diff --git a/examples/remoteobjects/clientapp/CMakeLists.txt b/examples/remoteobjects/clientapp/CMakeLists.txt index 13dec8b..63a3b3f 100644 --- a/examples/remoteobjects/clientapp/CMakeLists.txt +++ b/examples/remoteobjects/clientapp/CMakeLists.txt @@ -4,6 +4,7 @@ cmake_minimum_required(VERSION 3.16) project(clientapp LANGUAGES CXX) +set(CMAKE_INCLUDE_CURRENT_DIR ON) set(CMAKE_AUTOMOC ON) if(NOT DEFINED INSTALL_EXAMPLESDIR) @@ -14,16 +15,29 @@ set(INSTALL_EXAMPLEDIR "${INSTALL_EXAMPLESDIR}/remoteobjects/clientapp") find_package(Qt6 REQUIRED COMPONENTS Core Gui Quick RemoteObjects) +qt_standard_project_setup(REQUIRES 6.5) + qt_add_executable(clientapp + WIN32 + MACOSX_BUNDLE main.cpp ) -set_target_properties(clientapp PROPERTIES - WIN32_EXECUTABLE TRUE - MACOSX_BUNDLE TRUE +qt6_add_qml_module(clientapp + VERSION 1.0 + URI "TimeExample" + SOURCES + plugin.h plugin.cpp + QML_FILES + qml/Clock.qml + RESOURCES + qml/center.png + qml/clock.png + qml/hour.png + qml/minute.png ) -target_link_libraries(clientapp PUBLIC +target_link_libraries(clientapp PRIVATE Qt::Core Qt::Gui Qt::Quick @@ -45,6 +59,10 @@ qt6_add_resources(clientapp "clientapp" ${clientapp_resource_files} ) +qt6_add_repc_replicas(clientapp + ../timemodel.rep +) + install(TARGETS clientapp RUNTIME DESTINATION "${INSTALL_EXAMPLEDIR}" BUNDLE DESTINATION "${INSTALL_EXAMPLEDIR}" diff --git a/examples/remoteobjects/clientapp/clientapp.pro b/examples/remoteobjects/clientapp/clientapp.pro index 6d5a25d..4808fe5 100644 --- a/examples/remoteobjects/clientapp/clientapp.pro +++ b/examples/remoteobjects/clientapp/clientapp.pro @@ -1,9 +1,17 @@ -SOURCES += main.cpp +QT += remoteobjects quick -RESOURCES += \ - clientapp.qrc +CONFIG += qmltypes -QT += remoteobjects quick +REPC_REPLICA += $$PWD/../timemodel.rep +TARGET = clientapp + +QML_IMPORT_NAME = TimeExample +QML_IMPORT_MAJOR_VERSION = 1 + +SOURCES += main.cpp plugin.cpp +HEADERS += plugin.h + +RESOURCES += clientapp.qrc contains(QT_CONFIG, c++11): CONFIG += c++11 diff --git a/examples/remoteobjects/clientapp/clientapp.qrc b/examples/remoteobjects/clientapp/clientapp.qrc index 23bdb39..5003239 100644 --- a/examples/remoteobjects/clientapp/clientapp.qrc +++ b/examples/remoteobjects/clientapp/clientapp.qrc @@ -4,5 +4,10 @@ <file>qml/plugins.qml</file> <file>qml/plugins1.qml</file> <file>qml/plugins2.qml</file> + <file>qml/Clock.qml</file> + <file>qml/center.png</file> + <file>qml/clock.png</file> + <file>qml/hour.png</file> + <file>qml/minute.png</file> </qresource> </RCC> diff --git a/examples/remoteobjects/clientapp/doc/images/clientapp-example.webp b/examples/remoteobjects/clientapp/doc/images/clientapp-example.webp Binary files differnew file mode 100644 index 0000000..e7c72cd --- /dev/null +++ b/examples/remoteobjects/clientapp/doc/images/clientapp-example.webp diff --git a/examples/remoteobjects/clientapp/doc/src/clientapp.qdoc b/examples/remoteobjects/clientapp/doc/src/clientapp.qdoc new file mode 100644 index 0000000..d11f507 --- /dev/null +++ b/examples/remoteobjects/clientapp/doc/src/clientapp.qdoc @@ -0,0 +1,59 @@ +// Copyright (C) 2016 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GFDL-1.3-no-invariants-only + +/*! + \example clientapp + \title Time Client Application + \examplecategory {Input/Output} + \ingroup qtremoteobjects-examples + \meta tag {remoteobjects} + \brief A client who holds a replica of a time object from a server and displays the time in a clock. + + The Time Client Application opens a blue window with a message. When + you click once, it displays a clock. When you click again, two clocks, + then it repeats. The clock is defined in Clock.qml and uses the \c Time + QML-type, implemented in C++, to set the time of the clock using the time + on the server. + + \image clientapp-example.webp + + \section1 Before Running the Time Client Application + + To run this example, \l {Time Server Application} must already be running + on the same host as this application. It sets up a registry server and + hosts an instance of a subclass of the \c MinuteTimerSimpleSource class. + If it is not running, there will be an error message in the window. + + \section1 Defining Remote Objects using a REP-file + + The REP-file "timemodel.rep" in the parent directory of this application + is used to generate the header-files used by both applications. For this + application, the generated "rep_timemodel_replica.h" file defines + \c MinuteTimerReplica, the replica of \c MinuteTimer, and other related + classes. + + \section1 The TimeModel Class + + The \c TimeModel class in plugin.h and plugin.cpp implements the QML-type + \c Time. It contacts the registry server on localhost using the URL + "local:registry", acquires a replica, \c MinuteTimerReplica, and connects + to its signals. The properties are automatically updated. + + \section1 The QML Types + + The QML defined in "Clock.qml" draws a watch using the properties hours + and minutes. + + The application opens a window with the contents "plugins.qml". It changes + between displaying different content using a Loader, cycling for each + click between "plugins0.qml", "plugins1.qml", and "plugins2.qml". + + While "plugins0.qml" displays a blue screen with a message, the custom + QML-type \c Clock is used in "plugins1.qml", with the properties hours + and minutes set to the hour and minute properties of \c Time. The + "plugins2.qml" file is similar but displays two clocks. + + \snippet clientapp/qml/plugins1.qml 0 + + \sa {Time Server Application} +*/ diff --git a/examples/remoteobjects/clientapp/plugin.cpp b/examples/remoteobjects/clientapp/plugin.cpp new file mode 100644 index 0000000..f028f95 --- /dev/null +++ b/examples/remoteobjects/clientapp/plugin.cpp @@ -0,0 +1,35 @@ +// Copyright (C) 2017 Ford Motor Company +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause + +#include "plugin.h" + +// Implements a "TimeModel" class with hour and minute properties +// that change on-the-minute yet efficiently sleep the rest +// of the time. + +TimeModel::TimeModel(QObject *parent) : QObject(parent), m_replica(nullptr) +{ + m_client.setRegistryUrl(QUrl(QStringLiteral("local:registry"))); + m_replica.reset(m_client.acquire<MinuteTimerReplica>()); + connect(m_replica.get(), &MinuteTimerReplica::hourChanged, this, &TimeModel::timeChanged); + connect(m_replica.get(), &MinuteTimerReplica::minuteChanged, this, &TimeModel::timeChanged); + connect(m_replica.get(), &MinuteTimerReplica::timeChanged, this, &TimeModel::timeChanged); + connect(m_replica.get(), &MinuteTimerReplica::stateChanged, this, &TimeModel::isValidChanged); +} + +TimeModel::~TimeModel() { } + +int TimeModel::minute() const +{ + return m_replica->minute(); +} + +int TimeModel::hour() const +{ + return m_replica->hour(); +} + +bool TimeModel::isValid() const +{ + return m_replica->state() == QRemoteObjectReplica::Valid; +} diff --git a/examples/remoteobjects/clientapp/plugin.h b/examples/remoteobjects/clientapp/plugin.h new file mode 100644 index 0000000..e48e69f --- /dev/null +++ b/examples/remoteobjects/clientapp/plugin.h @@ -0,0 +1,42 @@ +// Copyright (C) 2017 Ford Motor Company +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause + +#include <QtQml/QQmlExtensionPlugin> +#include <QtQml/QQmlEngine> +#include <QtQml/qqml.h> +#include <QDebug> +#include <QDateTime> +#include <QBasicTimer> +#include <QCoreApplication> +#include <QRemoteObjectReplica> +#include <QRemoteObjectNode> +#include "rep_timemodel_replica.h" + +// A "TimeModel" class with hour and minute properties +// that change on-the-minute yet efficiently sleep the rest +// of the time. + +class TimeModel : public QObject +{ + Q_OBJECT + Q_PROPERTY(int hour READ hour NOTIFY timeChanged) + Q_PROPERTY(int minute READ minute NOTIFY timeChanged) + Q_PROPERTY(bool isValid READ isValid NOTIFY isValidChanged) + QML_NAMED_ELEMENT(Time) + +public: + TimeModel(QObject *parent = nullptr); + ~TimeModel() override; + + int minute() const; + int hour() const; + bool isValid() const; + +signals: + void timeChanged(); + void isValidChanged(); + +private: + QRemoteObjectNode m_client; + std::unique_ptr<MinuteTimerReplica> m_replica; +}; diff --git a/examples/remoteobjects/plugins/imports/TimeExample/Clock.qml b/examples/remoteobjects/clientapp/qml/Clock.qml index b2bf598..b620321 100644 --- a/examples/remoteobjects/plugins/imports/TimeExample/Clock.qml +++ b/examples/remoteobjects/clientapp/qml/Clock.qml @@ -1,7 +1,7 @@ // Copyright (C) 2017 Ford Motor Company // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause -import QtQuick 2.0 +import QtQuick Rectangle { id: clock @@ -11,6 +11,7 @@ Rectangle { property variant hours property variant minutes property variant shift : 0 + property variant valid : true Image { id: background; source: "clock.png" } @@ -48,4 +49,9 @@ Rectangle { id: cityLabel; font.bold: true; font.pixelSize: 14; y:200; color: "white" anchors.horizontalCenter: parent.horizontalCenter } + Text { + id: validity; font.bold: true; font.pixelSize: 14; y:100; color: "black" + anchors.horizontalCenter: parent.horizontalCenter + text: clock.valid ? "" : "Server not found" + } } diff --git a/examples/remoteobjects/plugins/imports/TimeExample/center.png b/examples/remoteobjects/clientapp/qml/center.png Binary files differindex 7fbd802..7fbd802 100644 --- a/examples/remoteobjects/plugins/imports/TimeExample/center.png +++ b/examples/remoteobjects/clientapp/qml/center.png diff --git a/examples/remoteobjects/plugins/imports/TimeExample/clock.png b/examples/remoteobjects/clientapp/qml/clock.png Binary files differindex 462edac..462edac 100644 --- a/examples/remoteobjects/plugins/imports/TimeExample/clock.png +++ b/examples/remoteobjects/clientapp/qml/clock.png diff --git a/examples/remoteobjects/plugins/imports/TimeExample/hour.png b/examples/remoteobjects/clientapp/qml/hour.png Binary files differindex f8061a1..f8061a1 100644 --- a/examples/remoteobjects/plugins/imports/TimeExample/hour.png +++ b/examples/remoteobjects/clientapp/qml/hour.png diff --git a/examples/remoteobjects/plugins/imports/TimeExample/minute.png b/examples/remoteobjects/clientapp/qml/minute.png Binary files differindex 1297ec7..1297ec7 100644 --- a/examples/remoteobjects/plugins/imports/TimeExample/minute.png +++ b/examples/remoteobjects/clientapp/qml/minute.png diff --git a/examples/remoteobjects/clientapp/qml/plugins.qml b/examples/remoteobjects/clientapp/qml/plugins.qml index 0139d24..2f608ad 100644 --- a/examples/remoteobjects/clientapp/qml/plugins.qml +++ b/examples/remoteobjects/clientapp/qml/plugins.qml @@ -1,7 +1,7 @@ // Copyright (C) 2017 Ford Motor Company // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause -import QtQuick 2.0 +import QtQuick Item { width: 200 diff --git a/examples/remoteobjects/clientapp/qml/plugins0.qml b/examples/remoteobjects/clientapp/qml/plugins0.qml index aa5ed68..32bc3cf 100644 --- a/examples/remoteobjects/clientapp/qml/plugins0.qml +++ b/examples/remoteobjects/clientapp/qml/plugins0.qml @@ -1,11 +1,22 @@ // Copyright (C) 2017 Ford Motor Company // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause //![0] -import QtQuick 2.0 +import QtQuick +import TimeExample // import types from the plugin Rectangle { width: 200 height: 400 color: "blue" + + Time { // this class is defined in C++ (plugin.cpp) + id: time + } + + Text { + id: validity; font.bold: true; font.pixelSize: 14; y:200; color: "white" + anchors.horizontalCenter: parent.horizontalCenter + text: time.isValid ? "Click to see clock!" : "Server not found" + } } //![0] diff --git a/examples/remoteobjects/clientapp/qml/plugins1.qml b/examples/remoteobjects/clientapp/qml/plugins1.qml index ba05d61..56c33a9 100644 --- a/examples/remoteobjects/clientapp/qml/plugins1.qml +++ b/examples/remoteobjects/clientapp/qml/plugins1.qml @@ -1,14 +1,14 @@ // Copyright (C) 2017 Ford Motor Company // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause //![0] -import QtQuick 2.0 -import TimeExample 1.0 // import types from the plugin +import QtQuick +import TimeExample // import types from the plugin Rectangle { width: 200 height: 400 color: "blue" - Clock { // this class is defined in QML (imports/TimeExample/Clock.qml) + Clock { id: clock1 anchors.top: parent.top Time { // this class is defined in C++ (plugin.cpp) @@ -17,6 +17,7 @@ Rectangle { hours: time.hour minutes: time.minute + valid: time.isValid } } diff --git a/examples/remoteobjects/clientapp/qml/plugins2.qml b/examples/remoteobjects/clientapp/qml/plugins2.qml index 576f3f8..2e82382 100644 --- a/examples/remoteobjects/clientapp/qml/plugins2.qml +++ b/examples/remoteobjects/clientapp/qml/plugins2.qml @@ -1,13 +1,13 @@ // Copyright (C) 2017 Ford Motor Company // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause //![0] -import QtQuick 2.0 -import TimeExample 1.0 // import types from the plugin +import QtQuick +import TimeExample // import types from the plugin Rectangle { width: 200 height: 400 - Clock { // this class is defined in QML (imports/TimeExample/Clock.qml) + Clock { // this class is defined in QML id: clock1 anchors.top: parent.top Time { // this class is defined in C++ (plugin.cpp) @@ -16,9 +16,10 @@ Rectangle { hours: time.hour minutes: time.minute + valid: time.isValid } - Clock { // this class is defined in QML (imports/TimeExample/Clock.qml) + Clock { // this class is defined in QML id: clock2 anchors.top: clock1.bottom Time { // this class is defined in C++ (plugin.cpp) @@ -27,6 +28,7 @@ Rectangle { hours: time2.hour minutes: time2.minute + valid: time2.isValid } diff --git a/examples/remoteobjects/plugins/imports/TimeExample/qmldir b/examples/remoteobjects/clientapp/qmldir index be259d4..e1a33a2 100644 --- a/examples/remoteobjects/plugins/imports/TimeExample/qmldir +++ b/examples/remoteobjects/clientapp/qmldir @@ -1,3 +1,3 @@ module TimeExample Clock 1.0 Clock.qml -plugin qmlqrotimeexampleplugin +plugin clientapp diff --git a/examples/remoteobjects/plugins/CMakeLists.txt b/examples/remoteobjects/plugins/CMakeLists.txt deleted file mode 100644 index c535c55..0000000 --- a/examples/remoteobjects/plugins/CMakeLists.txt +++ /dev/null @@ -1,49 +0,0 @@ -# Copyright (C) 2022 The Qt Company Ltd. -# SPDX-License-Identifier: BSD-3-Clause - -cmake_minimum_required(VERSION 3.16) -project(qmlqrotimeexampleplugin LANGUAGES CXX) - -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/plugins/imports/TimeExample") - -find_package(Qt6 REQUIRED COMPONENTS Core Gui Qml RemoteObjects) - -qt6_add_qml_module(qmlqrotimeexampleplugin - OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/imports/TimeExample" - VERSION 1.0 - URI "TimeExample" - RESOURCE_PREFIX / -) - -target_sources(qmlqrotimeexampleplugin PRIVATE - plugin.cpp -) - -set_target_properties(qmlqrotimeexampleplugin PROPERTIES - WIN32_EXECUTABLE TRUE - MACOSX_BUNDLE TRUE -) - -target_link_libraries(qmlqrotimeexampleplugin PUBLIC - Qt::Core - Qt::Gui - Qt::Qml - Qt::RemoteObjects -) - -qt6_add_repc_replicas(qmlqrotimeexampleplugin - ../timemodel.rep -) - -install(TARGETS qmlqrotimeexampleplugin - RUNTIME DESTINATION "${INSTALL_EXAMPLEDIR}" - BUNDLE DESTINATION "${INSTALL_EXAMPLEDIR}" - LIBRARY DESTINATION "${INSTALL_EXAMPLEDIR}" -) diff --git a/examples/remoteobjects/plugins/plugin.cpp b/examples/remoteobjects/plugins/plugin.cpp deleted file mode 100644 index 0232c5c..0000000 --- a/examples/remoteobjects/plugins/plugin.cpp +++ /dev/null @@ -1,92 +0,0 @@ -// Copyright (C) 2017 Ford Motor Company -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause - -#include <QtQml/QQmlExtensionPlugin> -#include <QtQml/QQmlEngine> -#include <QtQml/qqml.h> -#include <QDebug> -#include <QDateTime> -#include <QBasicTimer> -#include <QCoreApplication> -#include <QRemoteObjectReplica> -#include <QRemoteObjectNode> -#include "rep_timemodel_replica.h" - -// Implements a "TimeModel" class with hour and minute properties -// that change on-the-minute yet efficiently sleep the rest -// of the time. - -static QRemoteObjectNode m_client; - -class TimeModel : public QObject -{ - Q_OBJECT - Q_PROPERTY(int hour READ hour NOTIFY timeChanged) - Q_PROPERTY(int minute READ minute NOTIFY timeChanged) - Q_PROPERTY(bool isValid READ isValid NOTIFY isValidChanged) - -public: - TimeModel(QObject *parent = nullptr) : QObject(parent), d_ptr(nullptr) - { - d_ptr.reset(m_client.acquire< MinuteTimerReplica >()); - connect(d_ptr.data(), &MinuteTimerReplica::hourChanged, this, &TimeModel::timeChanged); - connect(d_ptr.data(), &MinuteTimerReplica::minuteChanged, this, &TimeModel::timeChanged); - connect(d_ptr.data(), &MinuteTimerReplica::timeChanged, this, &TimeModel::timeChanged); - connect(d_ptr.data(), &MinuteTimerReplica::timeChanged2, this, &TimeModel::test); - connect(d_ptr.data(), &MinuteTimerReplica::sendCustom, this, &TimeModel::testCustom); - } - - ~TimeModel() override - { - } - - int minute() const { return d_ptr->minute(); } - int hour() const { return d_ptr->hour(); } - bool isValid() const { return d_ptr->state() == QRemoteObjectReplica::Valid; } - -public slots: - //Test a signal with parameters - void test(QTime t) - { - qDebug()<<"Test"<<t; - d_ptr->SetTimeZone(t.minute()); - } - //Test a signal with a custom type - void testCustom(PresetInfo info) - { - qDebug()<<"testCustom"<<info.presetNumber()<<info.frequency()<<info.stationName(); - } - -signals: - void timeChanged(); - void timeChanged2(QTime t); - void sendCustom(PresetInfo info); - void isValidChanged(); - -private: - QScopedPointer<MinuteTimerReplica> d_ptr; -}; - -class QExampleQmlPlugin : public QQmlExtensionPlugin -{ - Q_OBJECT - Q_PLUGIN_METADATA(IID "org.qt-project.Qt.QQmlExtensionInterface") - -public: - void initializeEngine(QQmlEngine *engine, const char *uri) override - { - Q_UNUSED(engine) - Q_UNUSED(uri) - Q_ASSERT(uri == QLatin1String("TimeExample")); - engine->addImportPath(QStringLiteral("qrc:/qml")); - m_client.setRegistryUrl(QUrl(QStringLiteral("local:registry"))); - } - void registerTypes(const char *uri) override - { - Q_ASSERT(uri == QLatin1String("TimeExample")); - qmlRegisterType<TimeModel>(uri, 1, 0, "Time"); - } - -}; - -#include "plugin.moc" diff --git a/examples/remoteobjects/plugins/plugins.pro b/examples/remoteobjects/plugins/plugins.pro deleted file mode 100644 index 9d3f3d1..0000000 --- a/examples/remoteobjects/plugins/plugins.pro +++ /dev/null @@ -1,30 +0,0 @@ -QT += qml remoteobjects - -TEMPLATE = lib -CONFIG += plugin - -REPC_REPLICA += $$PWD/../timemodel.rep - -DESTDIR = imports/TimeExample -TARGET = qmlqrotimeexampleplugin - -SOURCES += plugin.cpp - -pluginfiles.files += \ - imports/TimeExample/qmldir \ - imports/TimeExample/center.png \ - imports/TimeExample/clock.png \ - imports/TimeExample/Clock.qml \ - imports/TimeExample/hour.png \ - imports/TimeExample/minute.png - -qml.files = plugins.qml -qml.path += $$[QT_INSTALL_EXAMPLES]/remoteobjects/plugins -target.path += $$[QT_INSTALL_EXAMPLES]/remoteobjects/plugins/imports/TimeExample -pluginfiles.path += $$[QT_INSTALL_EXAMPLES]/remoteobjects/plugins/imports/TimeExample - -INSTALLS += target qml pluginfiles - -CONFIG += install_ok # Do not cargo-cult this! - -contains(QT_CONFIG, c++11): CONFIG += c++11 diff --git a/examples/remoteobjects/plugins/plugins.qml b/examples/remoteobjects/plugins/plugins.qml deleted file mode 100644 index e631ee8..0000000 --- a/examples/remoteobjects/plugins/plugins.qml +++ /dev/null @@ -1,24 +0,0 @@ -// Copyright (C) 2014 Ford Motor Company -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause - -import QtQuick 2.0 - -Item { - width: 200 - height: 400 - property int counter: 0; - MouseArea { - anchors.fill: parent - onClicked: - { - counter = (counter + 1) % 3; - console.log(counter); - pageLoader.source = "plugins"+counter+".qml" - } - } - Loader { - id: pageLoader - source: "plugins0.qml" - } -} -//![0] diff --git a/examples/remoteobjects/plugins/plugins0.qml b/examples/remoteobjects/plugins/plugins0.qml deleted file mode 100644 index aa5ed68..0000000 --- a/examples/remoteobjects/plugins/plugins0.qml +++ /dev/null @@ -1,11 +0,0 @@ -// Copyright (C) 2017 Ford Motor Company -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause -//![0] -import QtQuick 2.0 - -Rectangle { - width: 200 - height: 400 - color: "blue" -} -//![0] diff --git a/examples/remoteobjects/plugins/plugins1.qml b/examples/remoteobjects/plugins/plugins1.qml deleted file mode 100644 index ba05d61..0000000 --- a/examples/remoteobjects/plugins/plugins1.qml +++ /dev/null @@ -1,23 +0,0 @@ -// Copyright (C) 2017 Ford Motor Company -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause -//![0] -import QtQuick 2.0 -import TimeExample 1.0 // import types from the plugin - -Rectangle { - width: 200 - height: 400 - color: "blue" - Clock { // this class is defined in QML (imports/TimeExample/Clock.qml) - id: clock1 - anchors.top: parent.top - Time { // this class is defined in C++ (plugin.cpp) - id: time - } - - hours: time.hour - minutes: time.minute - - } -} -//![0] diff --git a/examples/remoteobjects/plugins/plugins2.qml b/examples/remoteobjects/plugins/plugins2.qml deleted file mode 100644 index 576f3f8..0000000 --- a/examples/remoteobjects/plugins/plugins2.qml +++ /dev/null @@ -1,34 +0,0 @@ -// Copyright (C) 2017 Ford Motor Company -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause -//![0] -import QtQuick 2.0 -import TimeExample 1.0 // import types from the plugin - -Rectangle { - width: 200 - height: 400 - Clock { // this class is defined in QML (imports/TimeExample/Clock.qml) - id: clock1 - anchors.top: parent.top - Time { // this class is defined in C++ (plugin.cpp) - id: time - } - - hours: time.hour - minutes: time.minute - - } - Clock { // this class is defined in QML (imports/TimeExample/Clock.qml) - id: clock2 - anchors.top: clock1.bottom - Time { // this class is defined in C++ (plugin.cpp) - id: time2 - } - - hours: time2.hour - minutes: time2.minute - - } - -} -//![0] diff --git a/examples/remoteobjects/remoteobjects.pro b/examples/remoteobjects/remoteobjects.pro index 57f12f4..1a43a3a 100644 --- a/examples/remoteobjects/remoteobjects.pro +++ b/examples/remoteobjects/remoteobjects.pro @@ -16,7 +16,6 @@ contains(QT_CONFIG, ssl): SUBDIRS += ssl qtHaveModule(quick) { SUBDIRS += \ - plugins \ clientapp } diff --git a/examples/remoteobjects/remoteobjects_server/doc/images/remoteobjects-server-example.webp b/examples/remoteobjects/remoteobjects_server/doc/images/remoteobjects-server-example.webp Binary files differnew file mode 100644 index 0000000..e3bb3dd --- /dev/null +++ b/examples/remoteobjects/remoteobjects_server/doc/images/remoteobjects-server-example.webp diff --git a/examples/remoteobjects/remoteobjects_server/doc/src/remoteobjects_server.qdoc b/examples/remoteobjects/remoteobjects_server/doc/src/remoteobjects_server.qdoc new file mode 100644 index 0000000..1f9a2f1 --- /dev/null +++ b/examples/remoteobjects/remoteobjects_server/doc/src/remoteobjects_server.qdoc @@ -0,0 +1,45 @@ +// Copyright (C) 2016 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GFDL-1.3-no-invariants-only + +/*! + \example remoteobjects_server + \title Time Server Application + \examplecategory {Input/Output} + \ingroup qtremoteobjects-examples + \meta tag {remoteobjects} + \brief A server which shares a time object with connected clients. + + The Time Server Application instantiates a \c MinuteTimer object and + shares it with all connected \l {Time Client Application} + {Time Client Applications}. + + \image remoteobjects-server-example.webp + + \section1 Defining Remote Objects using a REP-file + + The REP-file "timemodel.rep" in the parent directory of the example + is used to generate the header-files used by both applications. + For this application, the generated "rep_timemodel_source.h" file + defines \c MinuteTimerSource, the the class to subclass for the + implementation of \c MinuteTimer, and other related classes. + + \section1 The TimeModel Class + + The \c TimeModel class in timemodel.h and timemodel.cpp implements the + time object to share. It uses a \c QBasicTimer to ensure that the + time is updated by calling the \c timerEvent member function. + + \snippet remoteobjects_server/timemodel.cpp 0 + + \section1 Sharing an Instance of TimeModel + + Instances of \c QRemoteObjectHost and a \c QRemoteObjectRegistryHost are + created to host an object and having a registry to find it. A + \c MinuteTimer object is then created and it is shared using the + \c enableRemoting member function of the \c QRemoteObjectRegistryHost + object. + + \snippet remoteobjects_server/main.cpp 0 + + \sa {Time Client Application} +*/ diff --git a/examples/remoteobjects/remoteobjects_server/main.cpp b/examples/remoteobjects/remoteobjects_server/main.cpp index 952b799..f55b45e 100644 --- a/examples/remoteobjects/remoteobjects_server/main.cpp +++ b/examples/remoteobjects/remoteobjects_server/main.cpp @@ -38,6 +38,7 @@ void SigIntHandler() } #endif +//![0] int main(int argc, char *argv[]) { QCoreApplication app(argc, argv); @@ -55,3 +56,4 @@ int main(int argc, char *argv[]) Q_UNUSED(timer) return app.exec(); } +//![0] diff --git a/examples/remoteobjects/remoteobjects_server/timemodel.cpp b/examples/remoteobjects/remoteobjects_server/timemodel.cpp index 91fc42c..933eec9 100644 --- a/examples/remoteobjects/remoteobjects_server/timemodel.cpp +++ b/examples/remoteobjects/remoteobjects_server/timemodel.cpp @@ -10,10 +10,13 @@ MinuteTimer::MinuteTimer(QObject *parent) : MinuteTimerSimpleSource(parent), zon setMinute(time.minute()); timer.start(60000-time.second()*1000, this); } + MinuteTimer::~MinuteTimer() { timer.stop(); } + +//![0] void MinuteTimer::timerEvent(QTimerEvent *) { QTime now = QTime::currentTime(); @@ -29,10 +32,9 @@ void MinuteTimer::timerEvent(QTimerEvent *) setHour(time.hour()); setMinute(time.minute()); emit timeChanged(); - emit timeChanged2(time); - static PresetInfo bla(3, 93.9f, "Best Station"); - emit sendCustom(bla); } +//![0] + void MinuteTimer::SetTimeZone(const int &zn) { qDebug()<<"SetTimeZone"<<zn; |