├── .tag ├── .gitreview ├── examples ├── webchannel │ ├── nodejs │ │ ├── CMakeLists.txt │ │ ├── package.json │ │ ├── README │ │ └── chatclient.js │ ├── qwclient │ │ ├── CMakeLists.txt │ │ ├── package.json │ │ ├── README │ │ └── qwclient.js │ ├── shared │ │ ├── CMakeLists.txt │ │ ├── websockettransport.h │ │ ├── websocketclientwrapper.h │ │ ├── websocketclientwrapper.cpp │ │ └── websockettransport.cpp │ ├── chatclient-html │ │ ├── CMakeLists.txt │ │ ├── doc │ │ │ ├── images │ │ │ │ └── chatclient-html.png │ │ │ └── src │ │ │ │ └── chatclient-html.qdoc │ │ └── chatclient.html │ ├── chatclient-qml │ │ ├── doc │ │ │ ├── images │ │ │ │ └── chatclient-qml.png │ │ │ └── src │ │ │ │ └── chatclient-qml.qdoc │ │ ├── main.cpp │ │ ├── MainForm.ui.qml │ │ ├── LoginForm.ui.qml │ │ ├── CMakeLists.txt │ │ └── qmlchatclient.qml │ ├── chatserver-cpp │ │ ├── doc │ │ │ ├── images │ │ │ │ └── chatserver-cpp.png │ │ │ └── src │ │ │ │ └── chatserver-cpp.qdoc │ │ ├── CMakeLists.txt │ │ ├── main.cpp │ │ ├── chatserver.h │ │ └── chatserver.cpp │ ├── standalone │ │ ├── doc │ │ │ ├── images │ │ │ │ └── standalone-screenshot.png │ │ │ └── src │ │ │ │ └── standalone.qdoc │ │ ├── dialog.h │ │ ├── dialog.cpp │ │ ├── core.h │ │ ├── dialog.ui │ │ ├── main.cpp │ │ ├── CMakeLists.txt │ │ └── index.html │ └── CMakeLists.txt └── CMakeLists.txt ├── tests ├── global │ └── global.cfg ├── benchmarks │ ├── CMakeLists.txt │ └── webchannel │ │ ├── CMakeLists.txt │ │ ├── tst_bench_qwebchannel.h │ │ └── tst_bench_qwebchannel.cpp ├── auto │ ├── CMakeLists.txt │ ├── qml │ │ ├── testwebchannel.h │ │ ├── CMakeLists.txt │ │ ├── testtransport.h │ │ ├── qml.cpp │ │ ├── testwebchannel.cpp │ │ ├── testtransport.cpp │ │ ├── testobject.h │ │ ├── testobject.cpp │ │ └── data │ │ │ ├── tst_bench.qml │ │ │ ├── Client.qml │ │ │ └── tst_multiclient.qml │ ├── webchannel │ │ ├── CMakeLists.txt │ │ └── tst_webchannel.h │ └── cmake │ │ └── CMakeLists.txt └── CMakeLists.txt ├── .cmake.conf ├── src ├── CMakeLists.txt ├── webchannel │ ├── Qt6WebChannelExtras.cmake.in │ ├── qwebchannelglobal.h │ ├── doc │ │ ├── src │ │ │ ├── examples.qdoc │ │ │ ├── qt6-changes.qdoc │ │ │ ├── external-resources.qdoc │ │ │ ├── module.qdoc │ │ │ ├── index.qdoc │ │ │ └── javascript.qdoc │ │ └── qtwebchannel.qdocconf │ ├── qwebchannelabstracttransport.h │ ├── qwebchannel_p.h │ ├── qwebchannelabstracttransport.cpp │ ├── CMakeLists.txt │ └── qwebchannel.h └── webchannelquick │ ├── qwebchannelquickglobal.h │ ├── CMakeLists.txt │ ├── qqmlwebchannelattached.cpp │ ├── qqmlwebchannelattached_p.h │ ├── qqmlwebchannel.h │ └── qqmlwebchannel.cpp ├── dist ├── REUSE.toml ├── changes-5.12.0 ├── changes-5.15.0 ├── changes-5.12.1 ├── changes-5.13.1 ├── changes-5.14.1 ├── changes-5.15.1 ├── changes-5.11.3 ├── changes-5.12.3 ├── changes-5.12.4 ├── changes-5.12.5 ├── changes-5.13.2 ├── changes-5.14.2 ├── changes-5.6.0 ├── changes-5.6.1 ├── changes-5.9.0 ├── changes-5.10.0 ├── changes-5.11.0 ├── changes-5.9.1 ├── changes-5.9.3 ├── changes-5.9.5 ├── changes-5.11.1 ├── changes-5.9.4 ├── changes-5.13.0 ├── changes-5.9.6 ├── changes-5.11.2 ├── changes-5.12.2 ├── changes-5.10.1 ├── changes-5.6.3 ├── changes-5.7.1 ├── changes-5.9.2 ├── changes-5.8.0 ├── changes-5.15.2 ├── changes-5.14.0 ├── changes-5.5.0 └── changes-5.7.0 ├── dependencies.yaml ├── coin ├── module_config.yaml └── axivion │ └── ci_config_linux.json ├── LICENSES ├── LicenseRef-Qt-Commercial.txt ├── BSD-3-Clause.txt └── LGPL-3.0-only.txt ├── CMakeLists.txt ├── REUSE.toml ├── README.md └── licenseRule.json /.tag: -------------------------------------------------------------------------------- 1 | c09bd1e4dca37d58a34dc9d221ad8fc2435a047d 2 | -------------------------------------------------------------------------------- /.gitreview: -------------------------------------------------------------------------------- 1 | [gerrit] 2 | host=codereview.qt-project.org 3 | project=qt/qtwebchannel 4 | defaultbranch=dev 5 | -------------------------------------------------------------------------------- /examples/webchannel/nodejs/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # Empty file required for supporting installation of example sources. 2 | -------------------------------------------------------------------------------- /examples/webchannel/qwclient/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # Empty file required for supporting installation of example sources. 2 | -------------------------------------------------------------------------------- /examples/webchannel/shared/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # Empty file required for supporting installation of example sources. 2 | -------------------------------------------------------------------------------- /examples/webchannel/chatclient-html/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # Empty file required for supporting installation of example sources. 2 | -------------------------------------------------------------------------------- /tests/global/global.cfg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /tests/benchmarks/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # Copyright (C) 2023 The Qt Company Ltd. 2 | # SPDX-License-Identifier: BSD-3-Clause 3 | 4 | add_subdirectory(webchannel) 5 | -------------------------------------------------------------------------------- /examples/webchannel/chatclient-qml/doc/images/chatclient-qml.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/qt/qtwebchannel/dev/examples/webchannel/chatclient-qml/doc/images/chatclient-qml.png -------------------------------------------------------------------------------- /examples/webchannel/chatserver-cpp/doc/images/chatserver-cpp.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/qt/qtwebchannel/dev/examples/webchannel/chatserver-cpp/doc/images/chatserver-cpp.png -------------------------------------------------------------------------------- /examples/webchannel/chatclient-html/doc/images/chatclient-html.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/qt/qtwebchannel/dev/examples/webchannel/chatclient-html/doc/images/chatclient-html.png -------------------------------------------------------------------------------- /examples/webchannel/standalone/doc/images/standalone-screenshot.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/qt/qtwebchannel/dev/examples/webchannel/standalone/doc/images/standalone-screenshot.png -------------------------------------------------------------------------------- /tests/auto/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # Copyright (C) 2022 The Qt Company Ltd. 2 | # SPDX-License-Identifier: BSD-3-Clause 3 | 4 | add_subdirectory(cmake) 5 | add_subdirectory(webchannel) 6 | if(TARGET Qt::Quick) 7 | add_subdirectory(qml) 8 | endif() 9 | -------------------------------------------------------------------------------- /.cmake.conf: -------------------------------------------------------------------------------- 1 | set(QT_REPO_MODULE_VERSION "6.12.0") 2 | set(QT_REPO_MODULE_PRERELEASE_VERSION_SEGMENT "alpha1") 3 | set(QT_EXTRA_INTERNAL_TARGET_DEFINES 4 | "QT_NO_FOREACH=1" 5 | "QT_NO_QASCONST=1" 6 | "QT_NO_URL_CAST_FROM_STRING=1" 7 | ) 8 | -------------------------------------------------------------------------------- /examples/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # Copyright (C) 2022 The Qt Company Ltd. 2 | # SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause 3 | 4 | qt_examples_build_begin(EXTERNAL_BUILD) 5 | 6 | add_subdirectory(webchannel) 7 | 8 | qt_examples_build_end() 9 | -------------------------------------------------------------------------------- /src/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # Copyright (C) 2022 The Qt Company Ltd. 2 | # SPDX-License-Identifier: BSD-3-Clause 3 | 4 | # Generated from src.pro. 5 | 6 | add_subdirectory(webchannel) 7 | if(TARGET Qt::Quick) 8 | add_subdirectory(webchannelquick) 9 | endif() 10 | -------------------------------------------------------------------------------- /src/webchannel/Qt6WebChannelExtras.cmake.in: -------------------------------------------------------------------------------- 1 | # Copyright (C) 2025 Menlo Systems GmbH; author Arno Rehn 2 | # SPDX-License-Identifier: BSD-3-Clause 3 | 4 | @PACKAGE_INIT@ 5 | 6 | set(QT_QWEBCHANNEL_JS_PATH "@PACKAGE_INSTALL_WEBCHANNEL_SHAREDIR@/qwebchannel.js") 7 | -------------------------------------------------------------------------------- /dist/REUSE.toml: -------------------------------------------------------------------------------- 1 | version = 1 2 | 3 | [[annotations]] 4 | path = ["*"] 5 | precedence = "override" 6 | comment = "Licensed as documentation." 7 | SPDX-FileCopyrightText = "Copyright (C) The Qt Company Ltd." 8 | SPDX-License-Identifier = "LicenseRef-Qt-Commercial OR GFDL-1.3-no-invariants-only" 9 | -------------------------------------------------------------------------------- /examples/webchannel/nodejs/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "Chatclient", 3 | "description": "Chatclient example", 4 | "author": "basysKom ", 5 | "version": "0.0.1", 6 | "dependencies": { 7 | "faye-websocket": "0.7.x" 8 | }, 9 | "engine": "node 0.10.x" 10 | } 11 | -------------------------------------------------------------------------------- /dependencies.yaml: -------------------------------------------------------------------------------- 1 | dependencies: 2 | ../qtbase: 3 | ref: df1292e2b96aab02ad6df778d8336e7958ad5d1c 4 | required: true 5 | ../qtdeclarative: 6 | ref: 7ef1d06ce70fa360613dca0b5ff03365ebbc9883 7 | required: false 8 | ../qtwebsockets: 9 | ref: ecf7bc43c93b4edd49e11e342a9beae900bd0680 10 | required: false 11 | -------------------------------------------------------------------------------- /tests/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # Copyright (C) 2022 The Qt Company Ltd. 2 | # SPDX-License-Identifier: BSD-3-Clause 3 | 4 | # Generated from tests.pro. 5 | 6 | if(QT_BUILD_STANDALONE_TESTS) 7 | # Add qt_find_package calls for extra dependencies that need to be found when building 8 | # the standalone tests here. 9 | endif() 10 | qt_build_tests() 11 | -------------------------------------------------------------------------------- /tests/benchmarks/webchannel/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # Copyright (C) 2023 The Qt Company Ltd. 2 | # SPDX-License-Identifier: BSD-3-Clause 3 | 4 | qt_internal_add_benchmark(tst_bench_qwebchannel 5 | SOURCES 6 | tst_bench_qwebchannel.cpp tst_bench_qwebchannel.h 7 | LIBRARIES 8 | Qt::CorePrivate 9 | Qt::WebChannel 10 | Qt::WebChannelPrivate 11 | Qt::Test 12 | ) 13 | -------------------------------------------------------------------------------- /src/webchannelquick/qwebchannelquickglobal.h: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2023 The Qt Company Ltd. 2 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only 3 | // Qt-Security score:significant reason:default 4 | 5 | #ifndef QTWEBCHANNELQUICK_H 6 | #define QTWEBCHANNELQUICK_H 7 | 8 | #include 9 | #include 10 | 11 | #endif // QTWEBCHANNELQUICK_H 12 | -------------------------------------------------------------------------------- /examples/webchannel/chatclient-qml/main.cpp: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2023 The Qt Company Ltd. 2 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause 3 | 4 | #include 5 | #include 6 | 7 | int main(int argc, char *argv[]) 8 | { 9 | QApplication app(argc, argv); 10 | 11 | QQmlApplicationEngine engine; 12 | engine.load(QUrl(QStringLiteral("qrc:/qmlchatclient.qml"))); 13 | 14 | return app.exec(); 15 | } 16 | -------------------------------------------------------------------------------- /coin/module_config.yaml: -------------------------------------------------------------------------------- 1 | version: 2 2 | accept_configuration: 3 | condition: property 4 | property: features 5 | not_contains_value: Disable 6 | 7 | instructions: 8 | Build: 9 | - type: EnvironmentVariable 10 | variableName: VERIFY_SOURCE_SBOM 11 | variableValue: "ON" 12 | - !include "{{qt/qtbase}}/coin_module_build_template_v2.yaml" 13 | Test: 14 | - !include "{{qt/qtbase}}/coin_module_test_template_v3.yaml" 15 | - !include "{{qt/qtbase}}/coin_module_test_docs.yaml" 16 | -------------------------------------------------------------------------------- /src/webchannel/qwebchannelglobal.h: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2016 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com, author Milian Wolff 2 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only 3 | // Qt-Security score:significant reason:default 4 | 5 | #ifndef QTWEBCHANNEL_H 6 | #define QTWEBCHANNEL_H 7 | 8 | #include 9 | #include 10 | 11 | #endif // QTWEBCHANNEL_H 12 | -------------------------------------------------------------------------------- /examples/webchannel/qwclient/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "qwclient", 3 | "description": "A generic REPL client for qwebchannel services using a websocket transport.", 4 | "author": "Sumedha Widyadharma ", 5 | "version": "0.0.1", 6 | "dependencies": { 7 | "faye-websocket": "0.7.x" 8 | }, 9 | "engine": "node 0.10.x", 10 | "repository": { 11 | "type": "git", 12 | "url": "git://gitorious.org/qt/qtwebchannel.git" 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /src/webchannel/doc/src/examples.qdoc: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2016 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com, author Milian Wolff 2 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GFDL-1.3-no-invariants-only 3 | 4 | /*! 5 | \title Qt WebChannel Examples 6 | \group qtwebchannel-examples 7 | \brief List of Qt WebChannel examples. 8 | 9 | The examples show how to use the QWebChannel C++ and \l [QML] WebChannel QML 10 | API. 11 | 12 | */ 13 | -------------------------------------------------------------------------------- /LICENSES/LicenseRef-Qt-Commercial.txt: -------------------------------------------------------------------------------- 1 | Licensees holding valid commercial Qt licenses may use this software in 2 | accordance with the the terms contained in a written agreement between 3 | you and The Qt Company. Alternatively, the terms and conditions that were 4 | accepted by the licensee when buying and/or downloading the 5 | software do apply. 6 | 7 | For the latest licensing terms and conditions, see https://www.qt.io/terms-conditions. 8 | For further information use the contact form at https://www.qt.io/contact-us. 9 | -------------------------------------------------------------------------------- /examples/webchannel/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # Copyright (C) 2022 The Qt Company Ltd. 2 | # SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause 3 | 4 | qt_internal_add_example(shared) 5 | 6 | qt_internal_add_example(nodejs) 7 | qt_internal_add_example(qwclient) 8 | qt_internal_add_example(chatclient-html) 9 | 10 | if(TARGET Qt::WebSockets AND NOT ANDROID) 11 | qt_internal_add_example(chatserver-cpp) 12 | endif() 13 | if(TARGET Qt::WebSockets AND TARGET Qt::Widgets) 14 | qt_internal_add_example(standalone) 15 | qt_internal_add_example(chatclient-qml) 16 | endif() 17 | -------------------------------------------------------------------------------- /src/webchannelquick/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # Copyright (C) 2022 The Qt Company Ltd. 2 | # SPDX-License-Identifier: BSD-3-Clause 3 | 4 | qt_internal_add_qml_module(WebChannelQuick 5 | URI "QtWebChannel" 6 | VERSION "${PROJECT_VERSION}" 7 | PAST_MAJOR_VERSIONS 1 8 | SOURCES 9 | qqmlwebchannel.h qqmlwebchannel.cpp 10 | qqmlwebchannelattached_p.h qqmlwebchannelattached.cpp 11 | qwebchannelquickglobal.h 12 | NO_PCH_SOURCES 13 | qqmlwebchannel.cpp # undef QT_NO_FOREACH 14 | DEFINES 15 | QT_NO_CONTEXTLESS_CONNECT 16 | LIBRARIES 17 | Qt::CorePrivate 18 | Qt::WebChannelPrivate 19 | ) 20 | -------------------------------------------------------------------------------- /examples/webchannel/nodejs/README: -------------------------------------------------------------------------------- 1 | This is a small NodeJS implementation on how to connect to a QWebChannel. 2 | 3 | This example implements a small chat client using the command line. It connects 4 | to the server provided by the other example 'examples/standalone/standalone'. Of 5 | course the port the server listens on must be known. 6 | 7 | How to run it: 8 | 9 | - Install NodeJS (at least 0.10.x) (http://www.nodejs.org/download/) 10 | - go to examples/nodejs and execute "npm install". This sets up the nodeJS 11 | environment in this folder 12 | - ensure examples/standalone/standalone is running 13 | - execute the example with "node chatclient.js" 14 | 15 | -------------------------------------------------------------------------------- /tests/auto/qml/testwebchannel.h: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2016 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com, author Milian Wolff 2 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only 3 | 4 | #ifndef TESTWEBCHANNEL_H 5 | #define TESTWEBCHANNEL_H 6 | 7 | #include 8 | 9 | QT_BEGIN_NAMESPACE 10 | 11 | class TestWebChannel : public QQmlWebChannel 12 | { 13 | Q_OBJECT 14 | 15 | public: 16 | explicit TestWebChannel(QObject *parent = 0); 17 | virtual ~TestWebChannel(); 18 | 19 | Q_INVOKABLE bool clientIsIdle() const; 20 | }; 21 | 22 | QT_END_NAMESPACE 23 | 24 | #endif // TESTWEBCHANNEL_H 25 | -------------------------------------------------------------------------------- /examples/webchannel/qwclient/README: -------------------------------------------------------------------------------- 1 | A REPL client for any qwebchannel service using a websocket transport. 2 | 3 | A nice tool for testing qwebchannel endpoints. 4 | 5 | Install: 6 | - qmake && make from the qwebchannel sources or examples. 7 | - npm install 8 | 9 | Usage: 10 | - qwclient.js 11 | - openChannel(url) in the REPL to open a new connection, multiple channels are OK 12 | - channel object lists are aliased to c i.e. c0, c1, ... 13 | 14 | Example using the standalone example server: 15 | - Launch standalone example server 16 | - qwclient localhost:12345 17 | - c0.receiveText('test') 18 | - 'test' should be displayed in the standalone server UI 19 | -------------------------------------------------------------------------------- /tests/auto/webchannel/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # Copyright (C) 2022 The Qt Company Ltd. 2 | # SPDX-License-Identifier: BSD-3-Clause 3 | 4 | qt_internal_add_test(tst_webchannel 5 | SOURCES 6 | tst_webchannel.cpp tst_webchannel.h 7 | LIBRARIES 8 | Qt::CorePrivate 9 | Qt::WebChannelPrivate 10 | Qt::TestPrivate 11 | ) 12 | 13 | qt_internal_extend_target(tst_webchannel CONDITION TARGET Qt::Qml 14 | DEFINES 15 | WEBCHANNEL_TESTS_CAN_USE_JS_ENGINE 16 | LIBRARIES 17 | Qt::Qml 18 | ) 19 | 20 | qt_internal_extend_target(tst_webchannel CONDITION TARGET Qt::Concurrent 21 | DEFINES 22 | WEBCHANNEL_TESTS_CAN_USE_CONCURRENT 23 | LIBRARIES 24 | Qt::Concurrent 25 | ) 26 | -------------------------------------------------------------------------------- /src/webchannel/doc/src/qt6-changes.qdoc: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2021 The Qt Company Ltd. 2 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GFDL-1.3-no-invariants-only 3 | 4 | /*! 5 | \page qtwebchannel-changes-qt6.html 6 | \title Changes to Qt WebChannel 7 | \ingroup changes-qt-5-to-6 8 | \brief Migrate Qt WebChannel to Qt 6. 9 | 10 | Qt 6 is a result of the conscious effort to make the framework more 11 | efficient and easy to use. 12 | 13 | We try to maintain binary and source compatibility for all the public 14 | APIs in each release. But some changes were inevitable in an effort to 15 | make Qt a better framework. 16 | 17 | In this topic we summarize those changes in Qt WebChannel, and provide guidance 18 | to handle them. 19 | 20 | */ 21 | -------------------------------------------------------------------------------- /dist/changes-5.12.0: -------------------------------------------------------------------------------- 1 | Qt 5.12 introduces many new features and improvements as well as bugfixes 2 | over the 5.11.x series. For more details, refer to the online documentation 3 | included in this distribution. The documentation is also available online: 4 | 5 | https://doc.qt.io/qt-5/index.html 6 | 7 | The Qt version 5.12 series is binary compatible with the 5.11.x series. 8 | Applications compiled for 5.11 will continue to run with 5.12. 9 | 10 | Some of the changes listed in this file include issue tracking numbers 11 | corresponding to tasks in the Qt Bug Tracker: 12 | 13 | https://bugreports.qt.io/ 14 | 15 | Each of these identifiers can be entered in the bug tracker to obtain more 16 | information about a particular change. 17 | 18 | - This release contains only minor code improvements. 19 | -------------------------------------------------------------------------------- /dist/changes-5.15.0: -------------------------------------------------------------------------------- 1 | Qt 5.15 introduces many new features and improvements as well as bugfixes 2 | over the 5.14.x series. For more details, refer to the online documentation 3 | included in this distribution. The documentation is also available online: 4 | 5 | https://doc.qt.io/qt-5/index.html 6 | 7 | The Qt version 5.15 series is binary compatible with the 5.14.x series. 8 | Applications compiled for 5.14 will continue to run with 5.15. 9 | 10 | Some of the changes listed in this file include issue tracking numbers 11 | corresponding to tasks in the Qt Bug Tracker: 12 | 13 | https://bugreports.qt.io/ 14 | 15 | Each of these identifiers can be entered in the bug tracker to obtain more 16 | information about a particular change. 17 | 18 | - This release contains only minor code improvements. 19 | -------------------------------------------------------------------------------- /examples/webchannel/standalone/dialog.h: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2017 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com, author Milian Wolff 2 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause 3 | 4 | #ifndef DIALOG_H 5 | #define DIALOG_H 6 | 7 | #include 8 | 9 | QT_BEGIN_NAMESPACE 10 | namespace Ui { 11 | class Dialog; 12 | } 13 | QT_END_NAMESPACE 14 | 15 | class Dialog : public QDialog 16 | { 17 | Q_OBJECT 18 | 19 | public: 20 | explicit Dialog(QWidget *parent = nullptr); 21 | 22 | void displayMessage(const QString &message); 23 | 24 | signals: 25 | void sendText(const QString &text); 26 | 27 | private slots: 28 | void clicked(); 29 | 30 | private: 31 | Ui::Dialog *ui; 32 | }; 33 | 34 | #endif // DIALOG_H 35 | -------------------------------------------------------------------------------- /tests/auto/qml/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # Copyright (C) 2022 The Qt Company Ltd. 2 | # SPDX-License-Identifier: BSD-3-Clause 3 | 4 | 5 | # Collect test data 6 | file(GLOB_RECURSE test_data_glob 7 | RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} 8 | data/*) 9 | list(APPEND test_data ${test_data_glob}) 10 | 11 | qt_internal_add_test(tst_qmlwebchannel 12 | QMLTEST 13 | QML_IMPORTPATH 14 | "${CMAKE_CURRENT_BINARY_DIR}/../../../qml" 15 | "${CMAKE_CURRENT_SOURCE_DIR}/data" 16 | SOURCES 17 | qml.cpp 18 | testobject.cpp testobject.h 19 | testtransport.cpp testtransport.h 20 | testwebchannel.cpp testwebchannel.h 21 | LIBRARIES 22 | Qt::CorePrivate 23 | Qt::WebChannelPrivate 24 | Qt::WebChannelQuick 25 | TESTDATA ${test_data} 26 | ) 27 | 28 | -------------------------------------------------------------------------------- /dist/changes-5.12.1: -------------------------------------------------------------------------------- 1 | Qt 5.12.1 is a bug-fix release. It maintains both forward and backward 2 | compatibility (source and binary) with Qt 5.12.0. 3 | 4 | For more details, refer to the online documentation included in this 5 | distribution. The documentation is also available online: 6 | 7 | http://doc.qt.io/qt-5/index.html 8 | 9 | The Qt version 5.12 series is binary compatible with the 5.11.x series. 10 | Applications compiled for 5.11 will continue to run with 5.12. 11 | 12 | Some of the changes listed in this file include issue tracking numbers 13 | corresponding to tasks in the Qt Bug Tracker: 14 | 15 | https://bugreports.qt.io/ 16 | 17 | Each of these identifiers can be entered in the bug tracker to obtain more 18 | information about a particular change. 19 | 20 | - This release contains only minor code improvements. 21 | -------------------------------------------------------------------------------- /dist/changes-5.13.1: -------------------------------------------------------------------------------- 1 | Qt 5.13.1 is a bug-fix release. It maintains both forward and backward 2 | compatibility (source and binary) with Qt 5.13.0. 3 | 4 | For more details, refer to the online documentation included in this 5 | distribution. The documentation is also available online: 6 | 7 | https://doc.qt.io/qt-5/index.html 8 | 9 | The Qt version 5.13 series is binary compatible with the 5.12.x series. 10 | Applications compiled for 5.12 will continue to run with 5.13. 11 | 12 | Some of the changes listed in this file include issue tracking numbers 13 | corresponding to tasks in the Qt Bug Tracker: 14 | 15 | https://bugreports.qt.io/ 16 | 17 | Each of these identifiers can be entered in the bug tracker to obtain more 18 | information about a particular change. 19 | 20 | - This release contains only minor code improvements. 21 | -------------------------------------------------------------------------------- /dist/changes-5.14.1: -------------------------------------------------------------------------------- 1 | Qt 5.14.1 is a bug-fix release. It maintains both forward and backward 2 | compatibility (source and binary) with Qt 5.14.0. 3 | 4 | For more details, refer to the online documentation included in this 5 | distribution. The documentation is also available online: 6 | 7 | https://doc.qt.io/qt-5/index.html 8 | 9 | The Qt version 5.14 series is binary compatible with the 5.13.x series. 10 | Applications compiled for 5.13 will continue to run with 5.14. 11 | 12 | Some of the changes listed in this file include issue tracking numbers 13 | corresponding to tasks in the Qt Bug Tracker: 14 | 15 | https://bugreports.qt.io/ 16 | 17 | Each of these identifiers can be entered in the bug tracker to obtain more 18 | information about a particular change. 19 | 20 | - This release contains only minor code improvements. 21 | -------------------------------------------------------------------------------- /dist/changes-5.15.1: -------------------------------------------------------------------------------- 1 | Qt 5.15.1 is a bug-fix release. It maintains both forward and backward 2 | compatibility (source and binary) with Qt 5.15.0. 3 | 4 | For more details, refer to the online documentation included in this 5 | distribution. The documentation is also available online: 6 | 7 | https://doc.qt.io/qt-5/index.html 8 | 9 | The Qt version 5.15 series is binary compatible with the 5.14.x series. 10 | Applications compiled for 5.14 will continue to run with 5.15. 11 | 12 | Some of the changes listed in this file include issue tracking numbers 13 | corresponding to tasks in the Qt Bug Tracker: 14 | 15 | https://bugreports.qt.io/ 16 | 17 | Each of these identifiers can be entered in the bug tracker to obtain more 18 | information about a particular change. 19 | 20 | - This release contains only minor code improvements. 21 | -------------------------------------------------------------------------------- /dist/changes-5.11.3: -------------------------------------------------------------------------------- 1 | Qt 5.11.3 is a bug-fix release. It maintains both forward and backward 2 | compatibility (source and binary) with Qt 5.11.0 through 5.11.2. 3 | 4 | For more details, refer to the online documentation included in this 5 | distribution. The documentation is also available online: 6 | 7 | http://doc.qt.io/qt-5/index.html 8 | 9 | The Qt version 5.11 series is binary compatible with the 5.10.x series. 10 | Applications compiled for 5.10 will continue to run with 5.11. 11 | 12 | Some of the changes listed in this file include issue tracking numbers 13 | corresponding to tasks in the Qt Bug Tracker: 14 | 15 | https://bugreports.qt.io/ 16 | 17 | Each of these identifiers can be entered in the bug tracker to obtain more 18 | information about a particular change. 19 | 20 | - This release contains only minor code improvements. 21 | -------------------------------------------------------------------------------- /dist/changes-5.12.3: -------------------------------------------------------------------------------- 1 | Qt 5.12.3 is a bug-fix release. It maintains both forward and backward 2 | compatibility (source and binary) with Qt 5.12.0 through 5.12.2. 3 | 4 | For more details, refer to the online documentation included in this 5 | distribution. The documentation is also available online: 6 | 7 | https://doc.qt.io/qt-5/index.html 8 | 9 | The Qt version 5.12 series is binary compatible with the 5.11.x series. 10 | Applications compiled for 5.11 will continue to run with 5.12. 11 | 12 | Some of the changes listed in this file include issue tracking numbers 13 | corresponding to tasks in the Qt Bug Tracker: 14 | 15 | https://bugreports.qt.io/ 16 | 17 | Each of these identifiers can be entered in the bug tracker to obtain more 18 | information about a particular change. 19 | 20 | - This release contains only minor code improvements. 21 | -------------------------------------------------------------------------------- /dist/changes-5.12.4: -------------------------------------------------------------------------------- 1 | Qt 5.12.4 is a bug-fix release. It maintains both forward and backward 2 | compatibility (source and binary) with Qt 5.12.0 through 5.12.3. 3 | 4 | For more details, refer to the online documentation included in this 5 | distribution. The documentation is also available online: 6 | 7 | https://doc.qt.io/qt-5/index.html 8 | 9 | The Qt version 5.12 series is binary compatible with the 5.11.x series. 10 | Applications compiled for 5.11 will continue to run with 5.12. 11 | 12 | Some of the changes listed in this file include issue tracking numbers 13 | corresponding to tasks in the Qt Bug Tracker: 14 | 15 | https://bugreports.qt.io/ 16 | 17 | Each of these identifiers can be entered in the bug tracker to obtain more 18 | information about a particular change. 19 | 20 | - This release contains only minor code improvements. 21 | -------------------------------------------------------------------------------- /dist/changes-5.12.5: -------------------------------------------------------------------------------- 1 | Qt 5.12.5 is a bug-fix release. It maintains both forward and backward 2 | compatibility (source and binary) with Qt 5.12.0 through 5.12.4. 3 | 4 | For more details, refer to the online documentation included in this 5 | distribution. The documentation is also available online: 6 | 7 | https://doc.qt.io/qt-5/index.html 8 | 9 | The Qt version 5.12 series is binary compatible with the 5.11.x series. 10 | Applications compiled for 5.11 will continue to run with 5.12. 11 | 12 | Some of the changes listed in this file include issue tracking numbers 13 | corresponding to tasks in the Qt Bug Tracker: 14 | 15 | https://bugreports.qt.io/ 16 | 17 | Each of these identifiers can be entered in the bug tracker to obtain more 18 | information about a particular change. 19 | 20 | - This release contains only minor code improvements. 21 | -------------------------------------------------------------------------------- /dist/changes-5.13.2: -------------------------------------------------------------------------------- 1 | Qt 5.13.2 is a bug-fix release. It maintains both forward and backward 2 | compatibility (source and binary) with Qt 5.13.0 through 5.13.1. 3 | 4 | For more details, refer to the online documentation included in this 5 | distribution. The documentation is also available online: 6 | 7 | https://doc.qt.io/qt-5/index.html 8 | 9 | The Qt version 5.13 series is binary compatible with the 5.12.x series. 10 | Applications compiled for 5.12 will continue to run with 5.13. 11 | 12 | Some of the changes listed in this file include issue tracking numbers 13 | corresponding to tasks in the Qt Bug Tracker: 14 | 15 | https://bugreports.qt.io/ 16 | 17 | Each of these identifiers can be entered in the bug tracker to obtain more 18 | information about a particular change. 19 | 20 | - This release contains only minor code improvements. 21 | -------------------------------------------------------------------------------- /dist/changes-5.14.2: -------------------------------------------------------------------------------- 1 | Qt 5.14.2 is a bug-fix release. It maintains both forward and backward 2 | compatibility (source and binary) with Qt 5.14.0 through 5.14.1. 3 | 4 | For more details, refer to the online documentation included in this 5 | distribution. The documentation is also available online: 6 | 7 | https://doc.qt.io/qt-5/index.html 8 | 9 | The Qt version 5.14 series is binary compatible with the 5.13.x series. 10 | Applications compiled for 5.13 will continue to run with 5.14. 11 | 12 | Some of the changes listed in this file include issue tracking numbers 13 | corresponding to tasks in the Qt Bug Tracker: 14 | 15 | https://bugreports.qt.io/ 16 | 17 | Each of these identifiers can be entered in the bug tracker to obtain more 18 | information about a particular change. 19 | 20 | - This release contains only minor code improvements. 21 | -------------------------------------------------------------------------------- /tests/auto/qml/testtransport.h: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2016 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com, author Milian Wolff 2 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only 3 | 4 | #ifndef TESTTRANSPORT_H 5 | #define TESTTRANSPORT_H 6 | 7 | #include 8 | 9 | QT_BEGIN_NAMESPACE 10 | 11 | class TestTransport : public QWebChannelAbstractTransport 12 | { 13 | Q_OBJECT 14 | public: 15 | explicit TestTransport(QObject *parent = 0); 16 | 17 | virtual void sendMessage(const QJsonObject &message) override; 18 | 19 | Q_INVOKABLE void receiveMessage(const QString &message); 20 | 21 | Q_SIGNALS: 22 | void sendMessageRequested(const QJsonObject &message); 23 | }; 24 | 25 | QT_END_NAMESPACE 26 | 27 | #endif // TESTTRANSPORT_H 28 | -------------------------------------------------------------------------------- /src/webchannel/doc/src/external-resources.qdoc: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2015 The Qt Company Ltd. 2 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GFDL-1.3-no-invariants-only 3 | 4 | /* 5 | The nolink entries prevent autolinking of each occurrence of 'WebChannel' 6 | 'WebEngine' or 'WebSocket' to the QML type. 7 | To link to the QML type, use explicit linking. For example: 8 | \l [QML] WebChannel 9 | \sa {QtWebChannel::}{WebChannel} 10 | */ 11 | /*! 12 | \externalpage nolink 13 | \title WebChannel 14 | \internal 15 | */ 16 | 17 | /*! 18 | \externalpage nolink 19 | \title WebEngine 20 | \internal 21 | */ 22 | 23 | /*! 24 | \externalpage nolink 25 | \title WebSockets 26 | \internal 27 | */ 28 | 29 | /*! 30 | \externalpage nolink 31 | \title WebSocket 32 | \internal 33 | */ 34 | -------------------------------------------------------------------------------- /tests/auto/qml/qml.cpp: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2016 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com, author Milian Wolff 2 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only 3 | 4 | #include 5 | #include 6 | 7 | #ifndef QUICK_TEST_SOURCE_DIR 8 | #define QUICK_TEST_SOURCE_DIR nullptr 9 | #endif 10 | 11 | #include "testtransport.h" 12 | #include "testwebchannel.h" 13 | #include "testobject.h" 14 | 15 | int main(int argc, char **argv) 16 | { 17 | qmlRegisterType("QtWebChannel.Tests", 1, 0, "TestTransport"); 18 | qmlRegisterType("QtWebChannel.Tests", 1, 0, "TestWebChannel"); 19 | qmlRegisterType("QtWebChannel.Tests", 1, 0, "TestObject"); 20 | 21 | return quick_test_main(argc, argv, "qml", QUICK_TEST_SOURCE_DIR); 22 | } 23 | -------------------------------------------------------------------------------- /tests/auto/qml/testwebchannel.cpp: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2016 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com, author Milian Wolff 2 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only 3 | 4 | #include "testwebchannel.h" 5 | 6 | #include 7 | #include 8 | 9 | QT_BEGIN_NAMESPACE 10 | 11 | TestWebChannel::TestWebChannel(QObject *parent) 12 | : QQmlWebChannel(parent) 13 | { 14 | 15 | } 16 | 17 | TestWebChannel::~TestWebChannel() 18 | { 19 | 20 | } 21 | 22 | bool TestWebChannel::clientIsIdle() const 23 | { 24 | for (auto *transport : QWebChannel::d_func()->transports) { 25 | if (QWebChannel::d_func()->publisher->isClientIdle(transport)) 26 | return true; 27 | } 28 | return false; 29 | } 30 | 31 | QT_END_NAMESPACE 32 | -------------------------------------------------------------------------------- /examples/webchannel/shared/websockettransport.h: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2016 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com, author Milian Wolff 2 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause 3 | 4 | #ifndef WEBSOCKETTRANSPORT_H 5 | #define WEBSOCKETTRANSPORT_H 6 | 7 | #include 8 | 9 | QT_BEGIN_NAMESPACE 10 | class QWebSocket; 11 | QT_END_NAMESPACE 12 | 13 | class WebSocketTransport : public QWebChannelAbstractTransport 14 | { 15 | Q_OBJECT 16 | public: 17 | explicit WebSocketTransport(QWebSocket *socket); 18 | virtual ~WebSocketTransport(); 19 | 20 | void sendMessage(const QJsonObject &message) override; 21 | 22 | private slots: 23 | void textMessageReceived(const QString &message); 24 | 25 | private: 26 | QWebSocket *m_socket; 27 | }; 28 | 29 | #endif // WEBSOCKETTRANSPORT_H 30 | -------------------------------------------------------------------------------- /examples/webchannel/shared/websocketclientwrapper.h: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2016 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com, author Milian Wolff 2 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause 3 | 4 | #ifndef WEBSOCKETCLIENTWRAPPER_H 5 | #define WEBSOCKETCLIENTWRAPPER_H 6 | 7 | #include 8 | 9 | class WebSocketTransport; 10 | 11 | QT_BEGIN_NAMESPACE 12 | class QWebSocketServer; 13 | QT_END_NAMESPACE 14 | 15 | class WebSocketClientWrapper : public QObject 16 | { 17 | Q_OBJECT 18 | 19 | public: 20 | WebSocketClientWrapper(QWebSocketServer *server, QObject *parent = nullptr); 21 | 22 | signals: 23 | void clientConnected(WebSocketTransport *client); 24 | 25 | private slots: 26 | void handleNewConnection(); 27 | 28 | private: 29 | QWebSocketServer *m_server; 30 | }; 31 | 32 | #endif // WEBSOCKETCLIENTWRAPPER_H 33 | -------------------------------------------------------------------------------- /examples/webchannel/standalone/dialog.cpp: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2017 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com, author Milian Wolff 2 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause 3 | 4 | #include "dialog.h" 5 | #include "ui_dialog.h" 6 | 7 | Dialog::Dialog(QWidget *parent) : 8 | QDialog(parent), 9 | ui(new Ui::Dialog) 10 | { 11 | ui->setupUi(this); 12 | connect(ui->send, &QPushButton::clicked, this, &Dialog::clicked); 13 | } 14 | 15 | void Dialog::displayMessage(const QString &message) 16 | { 17 | ui->output->appendPlainText(message); 18 | } 19 | 20 | void Dialog::clicked() 21 | { 22 | const QString text = ui->input->text(); 23 | 24 | if (text.isEmpty()) 25 | return; 26 | 27 | emit sendText(text); 28 | displayMessage(tr("Sent message: %1").arg(text)); 29 | 30 | ui->input->clear(); 31 | } 32 | -------------------------------------------------------------------------------- /dist/changes-5.6.0: -------------------------------------------------------------------------------- 1 | Qt 5.6 introduces many new features and improvements as well as bugfixes 2 | over the 5.5.x series. For more details, refer to the online documentation 3 | included in this distribution. The documentation is also available online: 4 | 5 | http://doc.qt.io/qt-5.6 6 | 7 | The Qt version 5.6 series is binary compatible with the 5.5.x series. 8 | Applications compiled for 5.5 will continue to run with 5.6. 9 | 10 | Some of the changes listed in this file include issue tracking numbers 11 | corresponding to tasks in the Qt Bug Tracker: 12 | 13 | http://bugreports.qt.io/ 14 | 15 | Each of these identifiers can be entered in the bug tracker to obtain more 16 | information about a particular change. 17 | 18 | **************************************************************************** 19 | * General * 20 | **************************************************************************** 21 | - This release contains only minor improvements. 22 | -------------------------------------------------------------------------------- /dist/changes-5.6.1: -------------------------------------------------------------------------------- 1 | Qt 5.6 introduces many new features and improvements as well as bugfixes 2 | over the 5.5.x series. For more details, refer to the online documentation 3 | included in this distribution. The documentation is also available online: 4 | 5 | http://doc.qt.io/qt-5.6 6 | 7 | The Qt version 5.6 series is binary compatible with the 5.5.x series. 8 | Applications compiled for 5.5 will continue to run with 5.6. 9 | 10 | Some of the changes listed in this file include issue tracking numbers 11 | corresponding to tasks in the Qt Bug Tracker: 12 | 13 | http://bugreports.qt.io/ 14 | 15 | Each of these identifiers can be entered in the bug tracker to obtain more 16 | information about a particular change. 17 | 18 | **************************************************************************** 19 | * General * 20 | **************************************************************************** 21 | - This release contains only minor improvements. 22 | -------------------------------------------------------------------------------- /dist/changes-5.9.0: -------------------------------------------------------------------------------- 1 | Qt 5.9 introduces many new features and improvements as well as bugfixes 2 | over the 5.8.x series. For more details, refer to the online documentation 3 | included in this distribution. The documentation is also available online: 4 | 5 | http://doc.qt.io/qt-5/index.html 6 | 7 | The Qt version 5.9 series is binary compatible with the 5.8.x series. 8 | Applications compiled for 5.8 will continue to run with 5.9. 9 | 10 | Some of the changes listed in this file include issue tracking numbers 11 | corresponding to tasks in the Qt Bug Tracker: 12 | 13 | https://bugreports.qt.io/ 14 | 15 | Each of these identifiers can be entered in the bug tracker to obtain more 16 | information about a particular change. 17 | 18 | **************************************************************************** 19 | * General * 20 | **************************************************************************** 21 | 22 | - This release contains only minor improvements. 23 | 24 | -------------------------------------------------------------------------------- /dist/changes-5.10.0: -------------------------------------------------------------------------------- 1 | Qt 5.10 introduces many new features and improvements as well as bugfixes 2 | over the 5.9.x series. For more details, refer to the online documentation 3 | included in this distribution. The documentation is also available online: 4 | 5 | http://doc.qt.io/qt-5/index.html 6 | 7 | The Qt version 5.10 series is binary compatible with the 5.9.x series. 8 | Applications compiled for 5.9 will continue to run with 5.10. 9 | 10 | Some of the changes listed in this file include issue tracking numbers 11 | corresponding to tasks in the Qt Bug Tracker: 12 | 13 | https://bugreports.qt.io/ 14 | 15 | Each of these identifiers can be entered in the bug tracker to obtain more 16 | information about a particular change. 17 | 18 | **************************************************************************** 19 | * Qt 5.10.0 Changes * 20 | **************************************************************************** 21 | 22 | - This release contains only minor code improvements. 23 | -------------------------------------------------------------------------------- /dist/changes-5.11.0: -------------------------------------------------------------------------------- 1 | Qt 5.11 introduces many new features and improvements as well as bugfixes 2 | over the 5.10.x series. For more details, refer to the online documentation 3 | included in this distribution. The documentation is also available online: 4 | 5 | http://doc.qt.io/qt-5/index.html 6 | 7 | The Qt version 5.11 series is binary compatible with the 5.10.x series. 8 | Applications compiled for 5.10 will continue to run with 5.11. 9 | 10 | Some of the changes listed in this file include issue tracking numbers 11 | corresponding to tasks in the Qt Bug Tracker: 12 | 13 | https://bugreports.qt.io/ 14 | 15 | Each of these identifiers can be entered in the bug tracker to obtain more 16 | information about a particular change. 17 | 18 | **************************************************************************** 19 | * Qt 5.11.0 Changes * 20 | **************************************************************************** 21 | 22 | - This release contains only minor code improvements. 23 | -------------------------------------------------------------------------------- /dist/changes-5.9.1: -------------------------------------------------------------------------------- 1 | Qt 5.9.1 is a bug-fix release. It maintains both forward and backward 2 | compatibility (source and binary) with Qt 5.9.0. 3 | 4 | For more details, refer to the online documentation included in this 5 | distribution. The documentation is also available online: 6 | 7 | http://doc.qt.io/qt-5/index.html 8 | 9 | The Qt version 5.9 series is binary compatible with the 5.8.x series. 10 | Applications compiled for 5.8 will continue to run with 5.9. 11 | 12 | Some of the changes listed in this file include issue tracking numbers 13 | corresponding to tasks in the Qt Bug Tracker: 14 | 15 | https://bugreports.qt.io/ 16 | 17 | Each of these identifiers can be entered in the bug tracker to obtain more 18 | information about a particular change. 19 | 20 | **************************************************************************** 21 | * Library * 22 | **************************************************************************** 23 | 24 | - This release contains only minor code improvements. 25 | -------------------------------------------------------------------------------- /dist/changes-5.9.3: -------------------------------------------------------------------------------- 1 | Qt 5.9.3 is a bug-fix release. It maintains both forward and backward 2 | compatibility (source and binary) with Qt 5.9.0. 3 | 4 | For more details, refer to the online documentation included in this 5 | distribution. The documentation is also available online: 6 | 7 | http://doc.qt.io/qt-5/index.html 8 | 9 | The Qt version 5.9 series is binary compatible with the 5.8.x series. 10 | Applications compiled for 5.8 will continue to run with 5.9. 11 | 12 | Some of the changes listed in this file include issue tracking numbers 13 | corresponding to tasks in the Qt Bug Tracker: 14 | 15 | https://bugreports.qt.io/ 16 | 17 | Each of these identifiers can be entered in the bug tracker to obtain more 18 | information about a particular change. 19 | 20 | **************************************************************************** 21 | * Qt 5.9.3 Changes * 22 | **************************************************************************** 23 | 24 | - This release contains only minor code improvements. 25 | -------------------------------------------------------------------------------- /dist/changes-5.9.5: -------------------------------------------------------------------------------- 1 | Qt 5.9.5 is a bug-fix release. It maintains both forward and backward 2 | compatibility (source and binary) with Qt 5.9.0. 3 | 4 | For more details, refer to the online documentation included in this 5 | distribution. The documentation is also available online: 6 | 7 | http://doc.qt.io/qt-5/index.html 8 | 9 | The Qt version 5.9 series is binary compatible with the 5.8.x series. 10 | Applications compiled for 5.9 will continue to run with 5.9. 11 | 12 | Some of the changes listed in this file include issue tracking numbers 13 | corresponding to tasks in the Qt Bug Tracker: 14 | 15 | https://bugreports.qt.io/ 16 | 17 | Each of these identifiers can be entered in the bug tracker to obtain more 18 | information about a particular change. 19 | 20 | **************************************************************************** 21 | * Qt 5.9.5 Changes * 22 | **************************************************************************** 23 | 24 | - This release contains only minor code improvements. 25 | -------------------------------------------------------------------------------- /dist/changes-5.11.1: -------------------------------------------------------------------------------- 1 | Qt 5.11.1 is a bug-fix release. It maintains both forward and backward 2 | compatibility (source and binary) with Qt 5.11.0. 3 | 4 | For more details, refer to the online documentation included in this 5 | distribution. The documentation is also available online: 6 | 7 | http://doc.qt.io/qt-5/index.html 8 | 9 | The Qt version 5.11 series is binary compatible with the 5.10.x series. 10 | Applications compiled for 5.10 will continue to run with 5.11. 11 | 12 | Some of the changes listed in this file include issue tracking numbers 13 | corresponding to tasks in the Qt Bug Tracker: 14 | 15 | https://bugreports.qt.io/ 16 | 17 | Each of these identifiers can be entered in the bug tracker to obtain more 18 | information about a particular change. 19 | 20 | **************************************************************************** 21 | * Qt 5.11.1 Changes * 22 | **************************************************************************** 23 | 24 | - This release contains only minor code improvements. 25 | -------------------------------------------------------------------------------- /dist/changes-5.9.4: -------------------------------------------------------------------------------- 1 | Qt 5.9.4 is a bug-fix release. It maintains both forward and backward 2 | compatibility (source and binary) with Qt 5.9.0. 3 | 4 | For more details, refer to the online documentation included in this 5 | distribution. The documentation is also available online: 6 | 7 | http://doc.qt.io/qt-5/index.html 8 | 9 | The Qt version 5.9 series is binary compatible with the 5.8.x series. 10 | Applications compiled for 5.8 will continue to run with 5.9. 11 | 12 | Some of the changes listed in this file include issue tracking numbers 13 | corresponding to tasks in the Qt Bug Tracker: 14 | 15 | https://bugreports.qt.io/ 16 | 17 | Each of these identifiers can be entered in the bug tracker to obtain more 18 | information about a particular change. 19 | 20 | **************************************************************************** 21 | * Qt 5.9.4 Changes * 22 | **************************************************************************** 23 | 24 | - This release contains only minor code improvements. 25 | 26 | -------------------------------------------------------------------------------- /dist/changes-5.13.0: -------------------------------------------------------------------------------- 1 | Qt 5.13 introduces many new features and improvements as well as bugfixes 2 | over the 5.12.x series. For more details, refer to the online documentation 3 | included in this distribution. The documentation is also available online: 4 | 5 | https://doc.qt.io/qt-5/index.html 6 | 7 | The Qt version 5.13 series is binary compatible with the 5.12.x series. 8 | Applications compiled for 5.12 will continue to run with 5.13. 9 | 10 | Some of the changes listed in this file include issue tracking numbers 11 | corresponding to tasks in the Qt Bug Tracker: 12 | 13 | https://bugreports.qt.io/ 14 | 15 | Each of these identifiers can be entered in the bug tracker to obtain more 16 | information about a particular change. 17 | 18 | **************************************************************************** 19 | * General * 20 | **************************************************************************** 21 | 22 | - [QTBUG-62388] Fix crash when wrapped objects are shared across multiple 23 | transports. 24 | -------------------------------------------------------------------------------- /dist/changes-5.9.6: -------------------------------------------------------------------------------- 1 | Qt 5.9.6 is a bug-fix release. It maintains both forward and backward 2 | compatibility (source and binary) with Qt 5.9.0 through 5.9.5. 3 | 4 | For more details, refer to the online documentation included in this 5 | distribution. The documentation is also available online: 6 | 7 | http://doc.qt.io/qt-5/index.html 8 | 9 | The Qt version 5.9 series is binary compatible with the 5.8.x series. 10 | Applications compiled for 5.8 will continue to run with 5.9. 11 | 12 | Some of the changes listed in this file include issue tracking numbers 13 | corresponding to tasks in the Qt Bug Tracker: 14 | 15 | https://bugreports.qt.io/ 16 | 17 | Each of these identifiers can be entered in the bug tracker to obtain more 18 | information about a particular change. 19 | 20 | **************************************************************************** 21 | * Qt 5.9.6 Changes * 22 | **************************************************************************** 23 | 24 | - This release contains only minor code improvements. 25 | -------------------------------------------------------------------------------- /dist/changes-5.11.2: -------------------------------------------------------------------------------- 1 | Qt 5.11.2 is a bug-fix release. It maintains both forward and backward 2 | compatibility (source and binary) with Qt 5.11.0 through 5.11.1. 3 | 4 | For more details, refer to the online documentation included in this 5 | distribution. The documentation is also available online: 6 | 7 | http://doc.qt.io/qt-5/index.html 8 | 9 | The Qt version 5.11 series is binary compatible with the 5.10.x series. 10 | Applications compiled for 5.10 will continue to run with 5.11. 11 | 12 | Some of the changes listed in this file include issue tracking numbers 13 | corresponding to tasks in the Qt Bug Tracker: 14 | 15 | https://bugreports.qt.io/ 16 | 17 | Each of these identifiers can be entered in the bug tracker to obtain more 18 | information about a particular change. 19 | 20 | **************************************************************************** 21 | * Qt 5.11.2 Changes * 22 | **************************************************************************** 23 | 24 | - This release contains only minor code improvements. 25 | -------------------------------------------------------------------------------- /src/webchannel/qwebchannelabstracttransport.h: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2016 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com, author Milian Wolff 2 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only 3 | // Qt-Security score:significant reason:default 4 | 5 | #ifndef QWEBCHANNELABSTRACTTRANSPORT_H 6 | #define QWEBCHANNELABSTRACTTRANSPORT_H 7 | 8 | #include 9 | #include 10 | 11 | QT_BEGIN_NAMESPACE 12 | 13 | class QJsonObject; 14 | class Q_WEBCHANNEL_EXPORT QWebChannelAbstractTransport : public QObject 15 | { 16 | Q_OBJECT 17 | public: 18 | explicit QWebChannelAbstractTransport(QObject *parent = nullptr); 19 | ~QWebChannelAbstractTransport() override; 20 | 21 | public Q_SLOTS: 22 | virtual void sendMessage(const QJsonObject &message) = 0; 23 | 24 | Q_SIGNALS: 25 | void messageReceived(const QJsonObject &message, QWebChannelAbstractTransport *transport); 26 | }; 27 | 28 | QT_END_NAMESPACE 29 | 30 | #endif // QWEBCHANNELABSTRACTTRANSPORT_H 31 | -------------------------------------------------------------------------------- /CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # Copyright (C) 2022 The Qt Company Ltd. 2 | # SPDX-License-Identifier: BSD-3-Clause 3 | 4 | # Generated from qtwebchannel.pro. 5 | 6 | cmake_minimum_required(VERSION 3.16) 7 | 8 | include(.cmake.conf) 9 | project(QtWebChannel 10 | VERSION "${QT_REPO_MODULE_VERSION}" 11 | DESCRIPTION "Qt WebChannel Libraries" 12 | HOMEPAGE_URL "https://qt.io/" 13 | LANGUAGES CXX C 14 | ) 15 | 16 | # Make sure we use the fixed BASE argument of qt_add_resource. 17 | set(QT_USE_FIXED_QT_ADD_RESOURCE_BASE TRUE) 18 | 19 | find_package(Qt6 ${PROJECT_VERSION} CONFIG REQUIRED COMPONENTS BuildInternals) 20 | 21 | # This should be called as early as possible, just after find_package(BuildInternals) where it is 22 | # defined. 23 | qt_internal_project_setup() 24 | 25 | find_package(Qt6 ${PROJECT_VERSION} CONFIG REQUIRED COMPONENTS Core) 26 | find_package(Qt6 ${PROJECT_VERSION} CONFIG OPTIONAL_COMPONENTS Concurrent Quick Test QuickTest 27 | WebSockets Widgets) 28 | 29 | if(INTEGRITY) 30 | message(NOTICE "Skipping the build as the condition \"NOT INTEGRITY\" is not met.") 31 | return() 32 | endif() 33 | qt_build_repo() 34 | -------------------------------------------------------------------------------- /dist/changes-5.12.2: -------------------------------------------------------------------------------- 1 | Qt 5.12.2 is a bug-fix release. It maintains both forward and backward 2 | compatibility (source and binary) with Qt 5.12.0 through 5.12.1. 3 | 4 | For more details, refer to the online documentation included in this 5 | distribution. The documentation is also available online: 6 | 7 | https://doc.qt.io/qt-5/index.html 8 | 9 | The Qt version 5.12 series is binary compatible with the 5.11.x series. 10 | Applications compiled for 5.11 will continue to run with 5.12. 11 | 12 | Some of the changes listed in this file include issue tracking numbers 13 | corresponding to tasks in the Qt Bug Tracker: 14 | 15 | https://bugreports.qt.io/ 16 | 17 | Each of these identifiers can be entered in the bug tracker to obtain more 18 | information about a particular change. 19 | 20 | **************************************************************************** 21 | * UNSPECIFIED * 22 | **************************************************************************** 23 | 24 | - Enum values and QFlags are now correctly converted to and 25 | from integers in the JS interface 26 | -------------------------------------------------------------------------------- /examples/webchannel/chatclient-qml/MainForm.ui.qml: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2017 The Qt Company Ltd. 2 | // Copyright (C) 2016 basysKom GmbH, author Bernd Lamecker 3 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause 4 | 5 | import QtQuick 6 | import QtQuick.Controls 7 | import QtQuick.Layouts 8 | 9 | Item { 10 | property alias chat: chat 11 | property alias userlist: userlist 12 | property alias message: message 13 | 14 | GridLayout { 15 | anchors.fill: parent 16 | rows: 2 17 | columns: 2 18 | 19 | ScrollView { 20 | Layout.fillWidth: true 21 | Layout.fillHeight: true 22 | 23 | Label { 24 | id: chat 25 | } 26 | } 27 | 28 | Label { 29 | id: userlist 30 | width: 150 31 | Layout.fillHeight: true 32 | } 33 | 34 | TextField { 35 | id: message 36 | height: 50 37 | Layout.fillWidth: true 38 | Layout.columnSpan: 2 39 | focus: true 40 | } 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /dist/changes-5.10.1: -------------------------------------------------------------------------------- 1 | Qt 5.10.1 is a bug-fix release. It maintains both forward and backward 2 | compatibility (source and binary) with Qt 5.10.0. 3 | 4 | For more details, refer to the online documentation included in this 5 | distribution. The documentation is also available online: 6 | 7 | http://doc.qt.io/qt-5/index.html 8 | 9 | The Qt version 5.10 series is binary compatible with the 5.9.x series. 10 | Applications compiled for 5.9 will continue to run with 5.10. 11 | 12 | Some of the changes listed in this file include issue tracking numbers 13 | corresponding to tasks in the Qt Bug Tracker: 14 | 15 | https://bugreports.qt.io/ 16 | 17 | Each of these identifiers can be entered in the bug tracker to obtain more 18 | information about a particular change. 19 | 20 | This release contains all fixes included in the Qt 5.9.4 release. 21 | 22 | **************************************************************************** 23 | * Qt 5.10.1 Changes * 24 | **************************************************************************** 25 | 26 | - This release contains only minor code improvements. 27 | -------------------------------------------------------------------------------- /src/webchannel/doc/src/module.qdoc: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2014 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com, author Milian Wolff 2 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GFDL-1.3-no-invariants-only 3 | 4 | /*! 5 | \module QtWebChannel 6 | \title Qt WebChannel C++ Classes 7 | \ingroup modules 8 | \qtvariable webchannel 9 | \since 5.4 10 | \brief List of C++ classes that provide the Qt WebChannel functionality. 11 | 12 | To use these classes in your application, use the following include 13 | statement: 14 | 15 | \code 16 | #include 17 | \endcode 18 | 19 | To link against the module, add this line to your \l qmake \c .pro file: 20 | 21 | \code 22 | QT += webchannel 23 | \endcode 24 | */ 25 | 26 | /*! 27 | \qmlmodule QtWebChannel 1.\QtMinorVersion 28 | \title Qt WebChannel QML Types 29 | \since 5.4 30 | \brief List of QML types that provide WebChannel functionality. 31 | 32 | The QML types are accessed by using: 33 | \qml \QtMinorVersion 34 | import QtWebChannel 1.\1 35 | \endqml 36 | */ 37 | -------------------------------------------------------------------------------- /examples/webchannel/chatclient-qml/LoginForm.ui.qml: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2017 The Qt Company Ltd. 2 | // Copyright (C) 2016 basysKom GmbH, author Bernd Lamecker 3 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause 4 | import QtQuick 5 | import QtQuick.Controls 6 | import QtQuick.Layouts 7 | 8 | Item { 9 | property alias userName: userName 10 | property alias loginButton: loginButton 11 | property alias nameInUseError: nameInUseError 12 | 13 | ColumnLayout { 14 | anchors.right: parent.right 15 | anchors.left: parent.left 16 | anchors.top: parent.top 17 | 18 | TextField { 19 | id: userName 20 | focus: true 21 | onEditingFinished: loginButton.clicked() 22 | Layout.alignment: Qt.AlignHCenter | Qt.AlignVCenter 23 | } 24 | 25 | Button { 26 | id: loginButton 27 | text: "Login" 28 | Layout.alignment: Qt.AlignHCenter | Qt.AlignVCenter 29 | } 30 | 31 | Label { 32 | id: nameInUseError 33 | text: "Name already in use" 34 | Layout.alignment: Qt.AlignHCenter | Qt.AlignVCenter 35 | } 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /dist/changes-5.6.3: -------------------------------------------------------------------------------- 1 | Qt 5.6.3 is a bug-fix release. It maintains both forward and backward 2 | compatibility (source and binary) with Qt 5.6.0. 3 | 4 | For more details, refer to the online documentation included in this 5 | distribution. The documentation is also available online: 6 | 7 | http://doc.qt.io/qt-5/index.html 8 | 9 | The Qt version 5.6 series is binary compatible with the 5.5.x series. 10 | Applications compiled for 5.5 will continue to run with 5.6. 11 | 12 | Some of the changes listed in this file include issue tracking numbers 13 | corresponding to tasks in the Qt Bug Tracker: 14 | 15 | https://bugreports.qt.io/ 16 | 17 | Each of these identifiers can be entered in the bug tracker to obtain more 18 | information about a particular change. 19 | 20 | **************************************************************************** 21 | * Library * 22 | **************************************************************************** 23 | 24 | - [QTBUG-47678][QTBUG-51366] Correctly forward objects via the webchannel 25 | that live in a separate thread. 26 | 27 | - [QTBUG-60250] Do not assert when unregistering an object before the 28 | webchannel was initialized. 29 | -------------------------------------------------------------------------------- /coin/axivion/ci_config_linux.json: -------------------------------------------------------------------------------- 1 | { 2 | "Project": { 3 | "BuildSystemIntegration": { 4 | "child_order": [ 5 | "GCCSetup", 6 | "CMake", 7 | "LinkLibraries" 8 | ] 9 | }, 10 | "CMake": { 11 | "_active": true, 12 | "_copy_from": "CMakeIntegration", 13 | "build_environment": {}, 14 | "build_options": "-j4", 15 | "generate_options": "--fresh", 16 | "generator": "Ninja" 17 | }, 18 | "GCCSetup": { 19 | "_active": true, 20 | "_copy_from": "Command", 21 | "build_command": "gccsetup --cc gcc --cxx g++ --config ../../../axivion/" 22 | }, 23 | "LinkLibraries": { 24 | "_active": true, 25 | "_copy_from": "AxivionLinker", 26 | "input_files": [ 27 | "build/lib/lib*.so*.ir", 28 | "build/qml/*/lib*.so*.ir" 29 | ], 30 | "ir": "build/$(env:TESTED_MODULE_COIN).ir" 31 | } 32 | }, 33 | "_Format": "1.0", 34 | "_Version": "7.6.2", 35 | "_VersionNum": [ 36 | 7, 37 | 6, 38 | 2, 39 | 12725 40 | ] 41 | } 42 | -------------------------------------------------------------------------------- /tests/auto/qml/testtransport.cpp: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2016 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com, author Milian Wolff 2 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only 3 | 4 | #include "testtransport.h" 5 | 6 | #include 7 | #include 8 | #include 9 | 10 | QT_BEGIN_NAMESPACE 11 | 12 | TestTransport::TestTransport(QObject *parent) 13 | : QWebChannelAbstractTransport(parent) 14 | { 15 | 16 | } 17 | 18 | void TestTransport::sendMessage(const QJsonObject &message) 19 | { 20 | emit sendMessageRequested(message); 21 | } 22 | 23 | void TestTransport::receiveMessage(const QString &message) 24 | { 25 | QJsonParseError error; 26 | QJsonDocument doc = QJsonDocument::fromJson(message.toUtf8(), &error); 27 | if (error.error) { 28 | qWarning("Failed to parse JSON message: %s\nError is: %s", 29 | qPrintable(message), qPrintable(error.errorString())); 30 | return; 31 | } else if (!doc.isObject()) { 32 | qWarning("Received JSON message that is not an object: %s", 33 | qPrintable(message)); 34 | return; 35 | } 36 | emit messageReceived(doc.object(), this); 37 | } 38 | 39 | QT_END_NAMESPACE 40 | -------------------------------------------------------------------------------- /dist/changes-5.7.1: -------------------------------------------------------------------------------- 1 | Qt 5.7.1 is a bug-fix release. It maintains both forward and backward 2 | compatibility (source and binary) with Qt 5.7.0. 3 | 4 | For more details, refer to the online documentation included in this 5 | distribution. The documentation is also available online: 6 | 7 | http://doc.qt.io/qt-5/index.html 8 | 9 | The Qt version 5.7 series is binary compatible with the 5.6.x series. 10 | Applications compiled for 5.6 will continue to run with 5.7. 11 | 12 | Some of the changes listed in this file include issue tracking numbers 13 | corresponding to tasks in the Qt Bug Tracker: 14 | 15 | https://bugreports.qt.io/ 16 | 17 | Each of these identifiers can be entered in the bug tracker to obtain more 18 | information about a particular change. 19 | 20 | **************************************************************************** 21 | * General * 22 | **************************************************************************** 23 | 24 | - [QTBUG-48198] C++ functions taking arguments of type QJsonValue, 25 | QJsonArray or QJsonObject can now be called via the Qt WebChannel. 26 | - [QTBUG-48198] QObject properties of type QJsonValue, QJsonArray or 27 | QJsonObject can now be set via the Qt WebChannel. 28 | -------------------------------------------------------------------------------- /src/webchannelquick/qqmlwebchannelattached.cpp: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2016 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com, author 2 | // Milian Wolff 3 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only 4 | // Qt-Security score:significant reason:default 5 | 6 | #include "qqmlwebchannelattached_p.h" 7 | 8 | QT_USE_NAMESPACE 9 | 10 | QQmlWebChannelAttached::QQmlWebChannelAttached(QObject *parent) : QObject(parent) { } 11 | 12 | QQmlWebChannelAttached::~QQmlWebChannelAttached() { } 13 | 14 | /*! 15 | \qmlattachedproperty string WebChannel::id 16 | 17 | \brief The identifier under which an object, registered to a WebChannel, is known to remote 18 | clients. 19 | 20 | This property must be set for every object that should be published over the WebChannel. 21 | While no restrictions are enforced on the format of the id, it is usually a good idea to 22 | choose a string that is also a valid JavaScript identifier. 23 | */ 24 | QString QQmlWebChannelAttached::id() const 25 | { 26 | return m_id; 27 | } 28 | 29 | void QQmlWebChannelAttached::setId(const QString &id) 30 | { 31 | if (id != m_id) { 32 | m_id = id; 33 | emit idChanged(id); 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /src/webchannel/qwebchannel_p.h: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2016 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com, author Milian Wolff 2 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only 3 | // Qt-Security score:significant reason:default 4 | 5 | #ifndef QWEBCHANNEL_P_H 6 | #define QWEBCHANNEL_P_H 7 | 8 | // 9 | // W A R N I N G 10 | // ------------- 11 | // 12 | // This file is not part of the Qt API. It exists purely as an 13 | // implementation detail. This header file may change from version to 14 | // version without notice, or even be removed. 15 | // 16 | // We mean it. 17 | // 18 | 19 | #include "qwebchannelglobal.h" 20 | 21 | #include 22 | #include 23 | 24 | QT_BEGIN_NAMESPACE 25 | 26 | class QJsonValue; 27 | class QWebChannelAbstractTransport; 28 | class QMetaObjectPublisher; 29 | 30 | class Q_WEBCHANNEL_EXPORT QWebChannelPrivate : public QObjectPrivate 31 | { 32 | Q_DECLARE_PUBLIC(QWebChannel) 33 | public: 34 | QList transports; 35 | QMetaObjectPublisher *publisher; 36 | 37 | void init(); 38 | 39 | void _q_transportDestroyed(QObject* object); 40 | }; 41 | 42 | QT_END_NAMESPACE 43 | 44 | #endif // QWEBCHANNEL_P_H 45 | -------------------------------------------------------------------------------- /dist/changes-5.9.2: -------------------------------------------------------------------------------- 1 | Qt 5.9.2 is a bug-fix release. It maintains both forward and backward 2 | compatibility (source and binary) with Qt 5.9.0. 3 | 4 | For more details, refer to the online documentation included in this 5 | distribution. The documentation is also available online: 6 | 7 | http://doc.qt.io/qt-5/index.html 8 | 9 | The Qt version 5.9 series is binary compatible with the 5.8.x series. 10 | Applications compiled for 5.8 will continue to run with 5.9. 11 | 12 | Some of the changes listed in this file include issue tracking numbers 13 | corresponding to tasks in the Qt Bug Tracker: 14 | 15 | https://bugreports.qt.io/ 16 | 17 | Each of these identifiers can be entered in the bug tracker to obtain more 18 | information about a particular change. 19 | 20 | **************************************************************************** 21 | * Qt 5.9.2 Changes * 22 | **************************************************************************** 23 | 24 | - [QTBUG-62045] Do not crash on non-QVariant return types. 25 | 26 | - [QTBUG-57654] Allow examples to be built without module sources, e.g. 27 | when using the examples as shipped with the binary Qt installer. 28 | 29 | - Modernize the examples to follow current Qt and QML best-practices. 30 | -------------------------------------------------------------------------------- /examples/webchannel/chatserver-cpp/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # Copyright (C) 2022 The Qt Company Ltd. 2 | # SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause 3 | 4 | cmake_minimum_required(VERSION 3.16) 5 | project(chatserver LANGUAGES CXX) 6 | 7 | if (ANDROID) 8 | message(FATAL_ERROR "This project cannot be built on Android.") 9 | endif() 10 | 11 | set(CMAKE_AUTOMOC ON) 12 | 13 | find_package(Qt6 REQUIRED COMPONENTS Core WebChannel WebSockets) 14 | 15 | qt_add_executable(chatserver 16 | ../shared/websocketclientwrapper.cpp ../shared/websocketclientwrapper.h 17 | ../shared/websockettransport.cpp ../shared/websockettransport.h 18 | chatserver.cpp chatserver.h 19 | main.cpp 20 | ) 21 | 22 | set_target_properties(chatserver PROPERTIES 23 | WIN32_EXECUTABLE FALSE 24 | MACOSX_BUNDLE TRUE 25 | ) 26 | 27 | target_link_libraries(chatserver PUBLIC 28 | Qt::Core 29 | Qt::WebChannel 30 | Qt::WebSockets 31 | ) 32 | 33 | install(TARGETS chatserver 34 | BUNDLE DESTINATION . 35 | RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}" 36 | LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}" 37 | ) 38 | qt_generate_deploy_app_script( 39 | TARGET chatserver 40 | OUTPUT_SCRIPT deploy_script 41 | NO_UNSUPPORTED_PLATFORM_ERROR 42 | ) 43 | install(SCRIPT ${deploy_script}) 44 | -------------------------------------------------------------------------------- /examples/webchannel/standalone/core.h: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2017 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com, author Milian Wolff 2 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause 3 | 4 | #ifndef CORE_H 5 | #define CORE_H 6 | 7 | #include "dialog.h" 8 | #include 9 | 10 | /* 11 | An instance of this class gets published over the WebChannel and is then accessible to HTML clients. 12 | */ 13 | class Core : public QObject 14 | { 15 | Q_OBJECT 16 | 17 | public: 18 | Core(Dialog *dialog, QObject *parent = nullptr) 19 | : QObject(parent), m_dialog(dialog) 20 | { 21 | connect(dialog, &Dialog::sendText, this, &Core::sendText); 22 | } 23 | 24 | signals: 25 | /* 26 | This signal is emitted from the C++ side and the text displayed on the HTML client side. 27 | */ 28 | void sendText(const QString &text); 29 | 30 | public slots: 31 | 32 | /* 33 | This slot is invoked from the HTML client side and the text displayed on the server side. 34 | */ 35 | void receiveText(const QString &text) 36 | { 37 | m_dialog->displayMessage(Dialog::tr("Received message: %1").arg(text)); 38 | } 39 | 40 | private: 41 | Dialog *m_dialog; 42 | }; 43 | 44 | #endif // CORE_H 45 | -------------------------------------------------------------------------------- /dist/changes-5.8.0: -------------------------------------------------------------------------------- 1 | Qt 5.8 introduces many new features and improvements as well as bugfixes 2 | over the 5.7.x series. For more details, refer to the online documentation 3 | included in this distribution. The documentation is also available online: 4 | 5 | http://doc.qt.io/qt-5/index.html 6 | 7 | The Qt version 5.8 series is binary compatible with the 5.7.x series. 8 | Applications compiled for 5.7 will continue to run with 5.8. 9 | 10 | Some of the changes listed in this file include issue tracking numbers 11 | corresponding to tasks in the Qt Bug Tracker: 12 | 13 | https://bugreports.qt.io/ 14 | 15 | Each of these identifiers can be entered in the bug tracker to obtain more 16 | information about a particular change. 17 | 18 | **************************************************************************** 19 | * General * 20 | **************************************************************************** 21 | 22 | General Improvements 23 | -------------------- 24 | 25 | - [QTBUG-48198] C++ functions taking arguments of type QJsonValue, 26 | QJsonArray or QJsonObject can now be called via the Qt WebChannel. 27 | - [QTBUG-48198] QObject properties of type QJsonValue, QJsonArray or 28 | QJsonObject can now be set via the Qt WebChannel. 29 | -------------------------------------------------------------------------------- /dist/changes-5.15.2: -------------------------------------------------------------------------------- 1 | Qt 5.15.2 is a bug-fix release. It maintains both forward and backward 2 | compatibility (source and binary) with Qt 5.15.1. 3 | 4 | For more details, refer to the online documentation included in this 5 | distribution. The documentation is also available online: 6 | 7 | https://doc.qt.io/qt-5.15/index.html 8 | 9 | The Qt version 5.15 series is binary compatible with the 5.14.x series. 10 | Applications compiled for 5.14 will continue to run with 5.15. 11 | 12 | Some of the changes listed in this file include issue tracking numbers 13 | corresponding to tasks in the Qt Bug Tracker: 14 | 15 | https://bugreports.qt.io/ 16 | 17 | Each of these identifiers can be entered in the bug tracker to obtain more 18 | information about a particular change. 19 | 20 | **************************************************************************** 21 | * Important Behavior Changes * 22 | **************************************************************************** 23 | 24 | **************************************************************************** 25 | * Library * 26 | **************************************************************************** 27 | 28 | 29 | General 30 | ------- 31 | 32 | - [QTBUG-84007] Fixed infinite recursion when dealing with self contained 33 | objects. 34 | 35 | -------------------------------------------------------------------------------- /examples/webchannel/standalone/dialog.ui: -------------------------------------------------------------------------------- 1 | 2 | 3 | Dialog 4 | 5 | 6 | 7 | 0 8 | 0 9 | 400 10 | 300 11 | 12 | 13 | 14 | Dialog 15 | 16 | 17 | 18 | 19 | 20 | Message Contents 21 | 22 | 23 | 24 | 25 | 26 | 27 | Send 28 | 29 | 30 | 31 | 32 | 33 | 34 | true 35 | 36 | 37 | Initializing WebChannel... 38 | 39 | 40 | false 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | -------------------------------------------------------------------------------- /examples/webchannel/chatserver-cpp/main.cpp: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2016 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com, author Milian Wolff 2 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause 3 | 4 | #include "chatserver.h" 5 | 6 | #include "../shared/websocketclientwrapper.h" 7 | #include "../shared/websockettransport.h" 8 | 9 | #include 10 | #include 11 | #include 12 | 13 | int main(int argc, char** argv) 14 | { 15 | QCoreApplication app(argc, argv); 16 | 17 | QWebSocketServer server(QStringLiteral("QWebChannel Standalone Example Server"), 18 | QWebSocketServer::NonSecureMode); 19 | if (!server.listen(QHostAddress::LocalHost, 12345)) { 20 | qFatal("Failed to open web socket server."); 21 | return 1; 22 | } 23 | 24 | // wrap WebSocket clients in QWebChannelAbstractTransport objects 25 | WebSocketClientWrapper clientWrapper(&server); 26 | 27 | // setup the channel 28 | QWebChannel channel; 29 | QObject::connect(&clientWrapper, &WebSocketClientWrapper::clientConnected, 30 | &channel, &QWebChannel::connectTo); 31 | 32 | // setup the dialog and publish it to the QWebChannel 33 | ChatServer* chatserver = new ChatServer(&app); 34 | channel.registerObject(QStringLiteral("chatserver"), chatserver); 35 | 36 | return app.exec(); 37 | } 38 | -------------------------------------------------------------------------------- /examples/webchannel/shared/websocketclientwrapper.cpp: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2016 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com, author Milian Wolff 2 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause 3 | 4 | #include "websocketclientwrapper.h" 5 | #include "websockettransport.h" 6 | 7 | #include 8 | 9 | /*! 10 | \brief Wraps connected QWebSockets clients in WebSocketTransport objects. 11 | 12 | This code is all that is required to connect incoming WebSockets to the WebChannel. Any kind 13 | of remote JavaScript client that supports WebSockets can thus receive messages and access the 14 | published objects. 15 | */ 16 | 17 | /*! 18 | Construct the client wrapper with the given parent. 19 | 20 | All clients connecting to the QWebSocketServer will be automatically wrapped 21 | in WebSocketTransport objects. 22 | */ 23 | WebSocketClientWrapper::WebSocketClientWrapper(QWebSocketServer *server, QObject *parent) 24 | : QObject(parent) 25 | , m_server(server) 26 | { 27 | connect(server, &QWebSocketServer::newConnection, 28 | this, &WebSocketClientWrapper::handleNewConnection); 29 | } 30 | 31 | /*! 32 | Wrap an incoming WebSocket connection in a WebSocketTransport object. 33 | */ 34 | void WebSocketClientWrapper::handleNewConnection() 35 | { 36 | emit clientConnected(new WebSocketTransport(m_server->nextPendingConnection())); 37 | } 38 | -------------------------------------------------------------------------------- /src/webchannelquick/qqmlwebchannelattached_p.h: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2016 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com, author 2 | // Milian Wolff 3 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only 4 | // Qt-Security score:significant reason:default 5 | 6 | #ifndef QQMLWEBCHANNELATTACHED_H 7 | #define QQMLWEBCHANNELATTACHED_H 8 | 9 | // 10 | // W A R N I N G 11 | // ------------- 12 | // 13 | // This file is not part of the Qt API. It exists purely as an 14 | // implementation detail. This header file may change from version to 15 | // version without notice, or even be removed. 16 | // 17 | // We mean it. 18 | // 19 | 20 | #include 21 | #include 22 | #include 23 | 24 | QT_BEGIN_NAMESPACE 25 | 26 | class Q_WEBCHANNELQUICK_EXPORT QQmlWebChannelAttached : public QObject 27 | { 28 | Q_OBJECT 29 | Q_PROPERTY(QString id READ id WRITE setId NOTIFY idChanged FINAL) 30 | QML_ANONYMOUS 31 | QML_ADDED_IN_VERSION(1, 0) 32 | public: 33 | explicit QQmlWebChannelAttached(QObject *parent = 0); 34 | virtual ~QQmlWebChannelAttached(); 35 | 36 | QString id() const; 37 | void setId(const QString &id); 38 | 39 | Q_SIGNALS: 40 | void idChanged(const QString &id); 41 | 42 | private: 43 | QString m_id; 44 | }; 45 | 46 | QT_END_NAMESPACE 47 | 48 | #endif // QQMLWEBCHANNELATTACHED_H 49 | -------------------------------------------------------------------------------- /LICENSES/BSD-3-Clause.txt: -------------------------------------------------------------------------------- 1 | Copyright (c) . 2 | 3 | Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 4 | 5 | 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 6 | 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. 7 | 3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. 8 | 9 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 10 | -------------------------------------------------------------------------------- /dist/changes-5.14.0: -------------------------------------------------------------------------------- 1 | Qt 5.14 introduces many new features and improvements as well as bugfixes 2 | over the 5.13.x series. For more details, refer to the online documentation 3 | included in this distribution. The documentation is also available online: 4 | 5 | https://doc.qt.io/qt-5/index.html 6 | 7 | The Qt version 5.14 series is binary compatible with the 5.13.x series. 8 | Applications compiled for 5.13 will continue to run with 5.14. 9 | 10 | Some of the changes listed in this file include issue tracking numbers 11 | corresponding to tasks in the Qt Bug Tracker: 12 | 13 | https://bugreports.qt.io/ 14 | 15 | Each of these identifiers can be entered in the bug tracker to obtain more 16 | information about a particular change. 17 | 18 | **************************************************************************** 19 | * QWebChannel * 20 | **************************************************************************** 21 | 22 | - General: 23 | * It is now possible to explicitly call overloaded methods or connect to 24 | overloaded signals by specifying the full method or signal signature 25 | in string form on the JavaScript side. 26 | * Send current property values when another transport is accessing a 27 | previously wrapped object. 28 | * Various improvements in the handling of nested wrapped objects. 29 | * Async calls to C++ methods from the JavaScript side will now return 30 | a Promise if no callback is given and the JavaScript runtime supports 31 | promises. 32 | -------------------------------------------------------------------------------- /examples/webchannel/chatclient-qml/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # Copyright (C) 2023 The Qt Company Ltd. 2 | # SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause 3 | 4 | cmake_minimum_required(VERSION 3.16) 5 | project(qmlchatclient LANGUAGES CXX) 6 | 7 | find_package(Qt6 REQUIRED COMPONENTS Core Gui Quick WebChannel Widgets) 8 | 9 | qt_standard_project_setup() 10 | 11 | qt_add_executable(qmlchatclient 12 | main.cpp 13 | ) 14 | 15 | set_target_properties(qmlchatclient PROPERTIES 16 | WIN32_EXECUTABLE TRUE 17 | MACOSX_BUNDLE TRUE 18 | ) 19 | 20 | target_link_libraries(qmlchatclient PRIVATE 21 | Qt::Core 22 | Qt::Gui 23 | Qt::Quick 24 | Qt::Widgets 25 | ) 26 | 27 | # Resources: 28 | set(data_resource_files 29 | "qmlchatclient.qml" 30 | "LoginForm.ui.qml" 31 | "MainForm.ui.qml" 32 | "${QT_QWEBCHANNEL_JS_PATH}" 33 | ) 34 | 35 | set_source_files_properties("${QT_QWEBCHANNEL_JS_PATH}" PROPERTIES 36 | QT_RESOURCE_ALIAS "qwebchannel.js" 37 | ) 38 | 39 | qt6_add_resources(qmlchatclient "data" 40 | PREFIX 41 | "/" 42 | FILES 43 | ${data_resource_files} 44 | ) 45 | 46 | install(TARGETS qmlchatclient 47 | BUNDLE DESTINATION . 48 | RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}" 49 | LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}" 50 | ) 51 | qt_generate_deploy_qml_app_script( 52 | TARGET qmlchatclient 53 | OUTPUT_SCRIPT deploy_script 54 | MACOS_BUNDLE_POST_BUILD 55 | NO_UNSUPPORTED_PLATFORM_ERROR 56 | DEPLOY_USER_QML_MODULES_ON_UNSUPPORTED_PLATFORM 57 | ) 58 | install(SCRIPT ${deploy_script}) 59 | -------------------------------------------------------------------------------- /dist/changes-5.5.0: -------------------------------------------------------------------------------- 1 | Qt 5.5 introduces many new features and improvements as well as bugfixes 2 | over the 5.4.x series. For more details, refer to the online documentation 3 | included in this distribution. The documentation is also available online: 4 | 5 | http://doc.qt.io/qt-5/index.html 6 | 7 | The Qt version 5.5 series is binary compatible with the 5.4.x series. 8 | Applications compiled for 5.5 will continue to run with 5.5. 9 | 10 | Some of the changes listed in this file include issue tracking numbers 11 | corresponding to tasks in the Qt Bug Tracker: 12 | 13 | https://bugreports.qt.io/ 14 | 15 | Each of these identifiers can be entered in the bug tracker to obtain more 16 | information about a particular change. 17 | 18 | **************************************************************************** 19 | * General * 20 | **************************************************************************** 21 | 22 | General Improvements 23 | -------------------- 24 | 25 | - Better support for objects containing child objects in properties, methods 26 | and emitted signals. Such children now get wrapped on the fly as well and 27 | are accessible to JavaScript clients. 28 | 29 | - Improved separation between and support for multiple clients connected to 30 | a single WebChannel server. 31 | 32 | New Examples 33 | -------------------- 34 | 35 | - qwclient: 36 | A REPL client for any qwebchannel service using a websocket transport. 37 | 38 | Documentation 39 | -------------------- 40 | 41 | - Reworded documentation to better explain the interaction with Qt WebEngine 42 | and plain JavaScript clients using WebSockets. 43 | 44 | -------------------------------------------------------------------------------- /examples/webchannel/chatserver-cpp/chatserver.h: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2016 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com, author Milian Wolff 2 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause 3 | 4 | #ifndef CHATSERVER_H 5 | #define CHATSERVER_H 6 | 7 | #include 8 | #include 9 | 10 | QT_BEGIN_NAMESPACE 11 | class QTimer; 12 | QT_END_NAMESPACE 13 | 14 | class ChatServer : public QObject 15 | { 16 | Q_OBJECT 17 | 18 | Q_PROPERTY(QStringList userList READ userList NOTIFY userListChanged) 19 | 20 | public: 21 | explicit ChatServer(QObject *parent = nullptr); 22 | virtual ~ChatServer(); 23 | 24 | public: 25 | //a user logs in with the given username 26 | Q_INVOKABLE bool login(const QString &userName); 27 | 28 | //the user logs out, will be removed from userlist immediately 29 | Q_INVOKABLE bool logout(const QString &userName); 30 | 31 | //a user sends a message to all other users 32 | Q_INVOKABLE bool sendMessage(const QString &user, const QString &msg); 33 | 34 | //response of the keep alive signal from a client. 35 | // This is used to detect disconnects. 36 | Q_INVOKABLE void keepAliveResponse(const QString &user); 37 | 38 | QStringList userList() const; 39 | 40 | protected slots: 41 | void sendKeepAlive(); 42 | void checkKeepAliveResponses(); 43 | 44 | signals: 45 | void newMessage(QString time, QString user, QString msg); 46 | void keepAlive(); 47 | void userListChanged(); 48 | void userCountChanged(); 49 | 50 | private: 51 | QStringList m_userList; 52 | QStringList m_stillAliveUsers; 53 | QTimer *m_keepAliveCheckTimer; 54 | }; 55 | 56 | #endif // CHATSERVER_H 57 | -------------------------------------------------------------------------------- /tests/auto/cmake/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # Copyright (C) 2022 The Qt Company Ltd. 2 | # SPDX-License-Identifier: BSD-3-Clause 3 | 4 | # This is an automatic test for the CMake configuration files. 5 | # To run it manually, 6 | # 1) mkdir build # Create a build directory 7 | # 2) cd build 8 | # 3) # Run cmake on this directory 9 | # `$qt_prefix/bin/qt-cmake ..` or `cmake -DCMAKE_PREFIX_PATH=/path/to/qt ..` 10 | # 4) ctest # Run ctest 11 | 12 | cmake_minimum_required(VERSION 3.16) 13 | project(webchannel_cmake_tests) 14 | enable_testing() 15 | 16 | set(required_packages Core WebChannel) 17 | 18 | # Setup the test when called as a completely standalone project. 19 | if(TARGET Qt6::Core) 20 | # Tests are built as part of the repository's build tree. 21 | # Setup paths so that the Qt packages are found. 22 | qt_internal_set_up_build_dir_package_paths() 23 | endif() 24 | 25 | find_package(Qt6 REQUIRED COMPONENTS ${required_packages}) 26 | 27 | # Setup common test variables which were previously set by ctest_testcase_common.prf. 28 | set(CMAKE_MODULES_UNDER_TEST "${required_packages}") 29 | 30 | foreach(qt_package ${CMAKE_MODULES_UNDER_TEST}) 31 | set(package_name "${QT_CMAKE_EXPORT_NAMESPACE}${qt_package}") 32 | if(${package_name}_FOUND) 33 | set(CMAKE_${qt_package}_MODULE_MAJOR_VERSION "${${package_name}_VERSION_MAJOR}") 34 | set(CMAKE_${qt_package}_MODULE_MINOR_VERSION "${${package_name}_VERSION_MINOR}") 35 | set(CMAKE_${qt_package}_MODULE_PATCH_VERSION "${${package_name}_VERSION_PATCH}") 36 | endif() 37 | endforeach() 38 | 39 | include("${_Qt6CTestMacros}") 40 | 41 | set(module_includes 42 | WebChannel QWebChannel 43 | ) 44 | 45 | _qt_internal_test_module_includes( 46 | ${module_includes} 47 | ) 48 | -------------------------------------------------------------------------------- /tests/auto/qml/testobject.h: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2017 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com, author Milian Wolff 2 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only 3 | 4 | 5 | #ifndef TESTOBJECT_H 6 | #define TESTOBJECT_H 7 | 8 | #include 9 | #include 10 | #include 11 | 12 | QT_BEGIN_NAMESPACE 13 | 14 | class TestObject : public QObject 15 | { 16 | Q_OBJECT 17 | Q_PROPERTY(QVariantMap objectMap READ objectMap CONSTANT) 18 | Q_PROPERTY(QString stringProperty READ stringProperty WRITE setStringProperty BINDABLE bindableStringProperty) 19 | public: 20 | explicit TestObject(QObject *parent = nullptr); 21 | ~TestObject(); 22 | 23 | QVariantMap objectMap() const; 24 | QString stringProperty() const; 25 | QBindable bindableStringProperty() { return &m_stringProperty; } 26 | 27 | Q_INVOKABLE QObject* createQObject(); 28 | 29 | public slots: 30 | void triggerSignals(); 31 | 32 | int testOverload(int i); 33 | QString testOverload(const QString &str); 34 | QString testOverload(const QString &str, int i); 35 | int testVariantType(const QVariant &val); 36 | bool testEmbeddedObjects(const QVariantList &list); 37 | void setStringProperty(const QString &stringProperty); 38 | 39 | signals: 40 | void testSignalBool(bool testBool); 41 | void testSignalInt(int testInt); 42 | 43 | void testOverloadSignal(int i); 44 | void testOverloadSignal(const QString &str); 45 | void testOverloadSignal(const QString &str, int i); 46 | 47 | private: 48 | QObject *embeddedObject; 49 | Q_OBJECT_BINDABLE_PROPERTY_WITH_ARGS(TestObject, QString, m_stringProperty, "foo") 50 | }; 51 | 52 | QT_END_NAMESPACE 53 | 54 | #endif // TESTOBJECT_H 55 | -------------------------------------------------------------------------------- /examples/webchannel/standalone/doc/src/standalone.qdoc: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2016 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com, author Milian Wolff 2 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GFDL-1.3-no-invariants-only 3 | 4 | /*! 5 | \example standalone 6 | \title Qt WebChannel Standalone Example 7 | \ingroup qtwebchannel-examples 8 | \image standalone-screenshot.png 9 | \examplecategory {Web Technologies} 10 | \brief A simple chat between a server and a remote client running in a 11 | browser. 12 | 13 | \e{Standalone} demonstrates how to use the QWebChannel C++ API to 14 | communicate with an external client. It is a simple chat between a C++ 15 | application and a remote HTML client running in your default browser. 16 | 17 | \include examples-run.qdocinc 18 | 19 | \section1 Communicating with a Remote Client 20 | 21 | The C++ application sets up a QWebChannel instance and publishes a \c Core 22 | object over it. For the remote client side, the \c {index.html} file 23 | is opened. Both show a dialog with the list of received messages and an input 24 | box to send messages to the other end. 25 | 26 | The \c Core emits the \c Core::sendText() signal when the user sends 27 | a message. The signal automatically gets propagated to the HTML client. 28 | When the user enters a message on the HTML side, \c Core::receiveText() 29 | is called. 30 | 31 | All communication between the HTML client and the C++ server is done 32 | over a WebSocket. The C++ side instantiates a QWebSocketServer and 33 | wraps incoming QWebSocket connections in QWebChannelAbstractTransport 34 | objects. These objects are then connected to the QWebChannel instance. 35 | 36 | \sa {Qt WebChannel JavaScript API} 37 | */ 38 | -------------------------------------------------------------------------------- /dist/changes-5.7.0: -------------------------------------------------------------------------------- 1 | Qt 5.7 introduces many new features and improvements as well as bugfixes 2 | over the 5.6.x series. Also, there is a change in the licensing terms. 3 | For more details, refer to the online documentation included in this 4 | distribution. The documentation is also available online: 5 | 6 | http://doc.qt.io/qt-5.7 7 | 8 | The Qt version 5.7 series is binary compatible with the 5.6.x series. 9 | Applications compiled for 5.6 will continue to run with 5.7. 10 | 11 | Some of the changes listed in this file include issue tracking numbers 12 | corresponding to tasks in the Qt Bug Tracker: 13 | 14 | http://bugreports.qt.io/ 15 | 16 | Each of these identifiers can be entered in the bug tracker to obtain more 17 | information about a particular change. 18 | 19 | **************************************************************************** 20 | * Important License Changes * 21 | **************************************************************************** 22 | 23 | This module is no longer available under LGPLv2.1. The libraries are 24 | now available under the following licenses: 25 | * Commercial License 26 | * GNU General Public License v2.0 (LICENSE.GPL2) and later 27 | * GNU Lesser General Public License v3.0 (LICENSE.LGPL3) 28 | 29 | The tools are now available under the following licenses: 30 | * Commercial License 31 | * GNU General Public License 3.0 (LICENSE.GPL3) with exceptions 32 | described in The Qt Company GPL Exception 1.0 (LICENSE.GPL3-EXCEPT) 33 | 34 | **************************************************************************** 35 | * General * 36 | **************************************************************************** 37 | - This release contains only minor improvements. 38 | -------------------------------------------------------------------------------- /examples/webchannel/standalone/main.cpp: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2016 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com, author Milian Wolff 2 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause 3 | 4 | #include "dialog.h" 5 | #include "core.h" 6 | #include "../shared/websocketclientwrapper.h" 7 | #include "../shared/websockettransport.h" 8 | 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | #include 16 | #include 17 | 18 | int main(int argc, char** argv) 19 | { 20 | QApplication app(argc, argv); 21 | 22 | // setup the QWebSocketServer 23 | QWebSocketServer server(QStringLiteral("QWebChannel Standalone Example Server"), QWebSocketServer::NonSecureMode); 24 | if (!server.listen(QHostAddress::LocalHost, 12345)) { 25 | qFatal("Failed to open web socket server."); 26 | return 1; 27 | } 28 | 29 | // wrap WebSocket clients in QWebChannelAbstractTransport objects 30 | WebSocketClientWrapper clientWrapper(&server); 31 | 32 | // setup the channel 33 | QWebChannel channel; 34 | QObject::connect(&clientWrapper, &WebSocketClientWrapper::clientConnected, 35 | &channel, &QWebChannel::connectTo); 36 | 37 | // setup the UI 38 | Dialog dialog; 39 | 40 | // setup the core and publish it to the QWebChannel 41 | Core core(&dialog); 42 | channel.registerObject(QStringLiteral("core"), &core); 43 | 44 | // open a browser window with the client HTML page 45 | QUrl url = QUrl::fromLocalFile(BUILD_DIR "/index.html"); 46 | QDesktopServices::openUrl(url); 47 | 48 | dialog.displayMessage(Dialog::tr("Initialization complete, opening browser at %1.").arg(url.toDisplayString())); 49 | dialog.show(); 50 | 51 | return app.exec(); 52 | } 53 | -------------------------------------------------------------------------------- /examples/webchannel/chatclient-html/doc/src/chatclient-html.qdoc: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2016 basysKom GmbH, author Bernd Lamecker 2 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GFDL-1.3-no-invariants-only 3 | 4 | /*! 5 | \example chatclient-html 6 | \title Qt WebChannel ChatClient HTML Example 7 | \ingroup qtwebchannel-examples 8 | \examplecategory {Web Technologies} 9 | \brief A HTML/JavaScript client that communicates over a WebSocket with a QWebChannel server. 10 | 11 | 12 | \image chatclient-html.png 13 | 14 | \e{ChatClient HTML} provides a simple QWebChannel client implemented using JavaScript and HTML. 15 | 16 | \section1 Running the Example 17 | 18 | To run the example, open the \c chatclient.html file in a browser. 19 | 20 | \section1 Implementing a Web Channel Client 21 | 22 | The client initializes a WebSocket connection to the chat server and receives an object 23 | containing all the necessary signals, slots, and properties for implementing a chat client. 24 | 25 | After login, the client can invoke the method \c sendMessage and receive the signal \c newMessage 26 | to send and receive messages. Furthermore, a \c userList property provides the names of 27 | all other connected clients. The list is automatically updated when its contents change. 28 | Also, the client responds to the server's keep alive signal which is needed to detect disconnected 29 | clients and remove them from the \c userList property. 30 | 31 | The example shows how basic elements can be used with the client JavaScript implementation of 32 | QWebChannel, like connecting to signals (\c newMessage), calling slots (\c sendMessage), and handling 33 | property changes (\c userList). 34 | 35 | The client is able to work with \l{Qt WebChannel ChatServer Example}. 36 | 37 | 38 | \sa {Qt WebChannel ChatServer Example}, {Qt WebChannel ChatClient QML Application} 39 | 40 | */ 41 | -------------------------------------------------------------------------------- /REUSE.toml: -------------------------------------------------------------------------------- 1 | version = 1 2 | 3 | [[annotations]] 4 | path = ["tests/auto/bic/data/*.txt"] 5 | precedence = "closest" 6 | comment = "test" 7 | SPDX-FileCopyrightText = "Copyright (C) The Qt Company Ltd." 8 | SPDX-License-Identifier = "LicenseRef-Qt-Commercial OR GPL-3.0-only" 9 | 10 | [[annotations]] 11 | path = [".cmake.conf", "**.yaml", "**.json", "**.cfg", ".pri", ".tag"] 12 | precedence = "closest" 13 | comment = "build system" 14 | SPDX-FileCopyrightText = "Copyright (C) The Qt Company Ltd." 15 | SPDX-License-Identifier = "BSD-3-Clause" 16 | 17 | [[annotations]] 18 | path = ["**/.gitattributes", "**.gitignore", "**.gitreview"] 19 | precedence = "closest" 20 | comment = "version control system. Infrastructure" 21 | SPDX-FileCopyrightText = "Copyright (C) The Qt Company Ltd." 22 | SPDX-License-Identifier = "LicenseRef-Qt-Commercial OR BSD-3-Clause" 23 | 24 | [[annotations]] 25 | path = ["examples/**"] 26 | comment = "this must be after the build system table because example and snippets take precedence over build system" 27 | precedence = "closest" 28 | SPDX-FileCopyrightText = "Copyright (C) The Qt Company Ltd." 29 | SPDX-License-Identifier = "LicenseRef-Qt-Commercial OR BSD-3-Clause" 30 | 31 | [[annotations]] 32 | path = ["**/doc/images/**", "**/README*", "**.qdocconf"] 33 | comment = "documentation" 34 | precedence = "closest" 35 | SPDX-FileCopyrightText = "Copyright (C) The Qt Company Ltd." 36 | SPDX-License-Identifier = "LicenseRef-Qt-Commercial OR GFDL-1.3-no-invariants-only" 37 | 38 | [[annotations]] 39 | path = ["**.toml", "licenseRule.json"] 40 | comment = "infrastructure" 41 | precedence = "override" 42 | SPDX-FileCopyrightText = "Copyright (C) The Qt Company Ltd." 43 | SPDX-License-Identifier = "LicenseRef-Qt-Commercial OR BSD-3-Clause" 44 | 45 | [[annotations]] 46 | path = ["**/qt_attribution.json"] 47 | comment = "documentation" 48 | precedence = "override" 49 | SPDX-FileCopyrightText = "Copyright (C) The Qt Company Ltd." 50 | SPDX-License-Identifier = "LicenseRef-Qt-Commercial OR GFDL-1.3-no-invariants-only" 51 | -------------------------------------------------------------------------------- /examples/webchannel/standalone/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # Copyright (C) 2022 The Qt Company Ltd. 2 | # SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause 3 | 4 | cmake_minimum_required(VERSION 3.16) 5 | project(standalone LANGUAGES CXX) 6 | 7 | set(CMAKE_AUTOMOC ON) 8 | set(CMAKE_AUTOUIC ON) 9 | 10 | find_package(Qt6 REQUIRED COMPONENTS Core Gui WebChannel WebSockets Widgets) 11 | 12 | qt_add_executable(standalone 13 | ../shared/websocketclientwrapper.cpp ../shared/websocketclientwrapper.h 14 | ../shared/websockettransport.cpp ../shared/websockettransport.h 15 | core.h 16 | dialog.cpp dialog.h dialog.ui 17 | main.cpp 18 | ) 19 | 20 | set_target_properties(standalone PROPERTIES 21 | WIN32_EXECUTABLE TRUE 22 | MACOSX_BUNDLE TRUE 23 | ) 24 | 25 | # pro2cmake generates invalid cmake syntax here 26 | target_compile_definitions(standalone PUBLIC 27 | "BUILD_DIR=\"${CMAKE_CURRENT_BINARY_DIR}\"" 28 | ) 29 | 30 | target_link_libraries(standalone PUBLIC 31 | Qt::Core 32 | Qt::Gui 33 | Qt::WebChannel 34 | Qt::WebSockets 35 | Qt::Widgets 36 | ) 37 | 38 | add_custom_command( 39 | OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/qwebchannel.js 40 | COMMAND ${CMAKE_COMMAND} -E copy 41 | ${QT_QWEBCHANNEL_JS_PATH} 42 | ${CMAKE_CURRENT_BINARY_DIR}/qwebchannel.js 43 | DEPENDS ${QT_QWEBCHANNEL_JS_PATH} 44 | VERBATIM 45 | ) 46 | 47 | if (NOT CMAKE_CURRENT_BINARY_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR) 48 | add_custom_command( 49 | OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/index.html 50 | COMMAND ${CMAKE_COMMAND} -E copy 51 | ${CMAKE_CURRENT_SOURCE_DIR}/index.html 52 | ${CMAKE_CURRENT_BINARY_DIR}/index.html 53 | DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/index.html 54 | VERBATIM 55 | ) 56 | endif() 57 | 58 | add_custom_target(output_target ALL 59 | DEPENDS 60 | ${CMAKE_CURRENT_BINARY_DIR}/index.html 61 | ${CMAKE_CURRENT_BINARY_DIR}/qwebchannel.js 62 | ) 63 | 64 | add_dependencies(standalone output_target) 65 | -------------------------------------------------------------------------------- /src/webchannel/qwebchannelabstracttransport.cpp: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2016 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com, author Milian Wolff 2 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only 3 | // Qt-Security score:significant reason:default 4 | 5 | #include "qwebchannelabstracttransport.h" 6 | 7 | QT_BEGIN_NAMESPACE 8 | 9 | /*! 10 | \class QWebChannelAbstractTransport 11 | 12 | \inmodule QtWebChannel 13 | \brief Communication channel between the C++ QWebChannel server and a HTML/JS client. 14 | \since 5.4 15 | 16 | Users of the QWebChannel must implement this interface and connect instances of it 17 | to the QWebChannel server for every client that should be connected to the QWebChannel. 18 | The \l{Qt WebChannel Standalone Example} shows how this can be done 19 | using \l{Qt WebSockets}. 20 | 21 | \note The JSON message protocol is considered internal and might change over time. 22 | 23 | \sa {Qt WebChannel Standalone Example} 24 | */ 25 | 26 | /*! 27 | \fn QWebChannelAbstractTransport::messageReceived(const QJsonObject &message, QWebChannelAbstractTransport *transport) 28 | 29 | This signal must be emitted when a new JSON \a message was received from the remote client. The 30 | \a transport argument should be set to this transport object. 31 | */ 32 | 33 | /*! 34 | \fn QWebChannelAbstractTransport::sendMessage(const QJsonObject &message) 35 | 36 | Sends a JSON \a message to the remote client. An implementation would serialize the message and 37 | transmit it to the remote JavaScript client. 38 | */ 39 | 40 | /*! 41 | Constructs a transport object with the given \a parent. 42 | */ 43 | QWebChannelAbstractTransport::QWebChannelAbstractTransport(QObject *parent) 44 | : QObject(parent) 45 | { 46 | 47 | } 48 | 49 | /*! 50 | Destroys the transport object. 51 | */ 52 | QWebChannelAbstractTransport::~QWebChannelAbstractTransport() 53 | { 54 | 55 | } 56 | 57 | QT_END_NAMESPACE 58 | -------------------------------------------------------------------------------- /src/webchannel/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # Copyright (C) 2022 The Qt Company Ltd. 2 | # SPDX-License-Identifier: BSD-3-Clause 3 | 4 | if(QT6_INSTALL_QT_SHAREDIR) 5 | set(INSTALL_WEBCHANNEL_SHAREDIR "${QT6_INSTALL_QT_SHAREDIR}/webchannel") 6 | else() 7 | set(INSTALL_WEBCHANNEL_SHAREDIR "${INSTALL_QT_SHAREDIR}/webchannel") 8 | endif() 9 | 10 | include(CMakePackageConfigHelpers) 11 | 12 | set(target "WebChannel") 13 | set(path_suffix "${INSTALL_CMAKE_NAMESPACE}${target}") 14 | qt_path_join(config_build_dir ${QT_CONFIG_BUILD_DIR} ${path_suffix}) 15 | qt_path_join(config_install_dir ${QT_CONFIG_INSTALL_DIR} ${path_suffix}) 16 | 17 | configure_package_config_file( 18 | Qt6WebChannelExtras.cmake.in 19 | "${config_build_dir}/Qt6WebChannelExtras.cmake" 20 | INSTALL_DESTINATION "${config_install_dir}" 21 | PATH_VARS INSTALL_WEBCHANNEL_SHAREDIR 22 | ) 23 | 24 | qt_internal_add_module(WebChannel 25 | SOURCES 26 | qmetaobjectpublisher.cpp qmetaobjectpublisher_p.h 27 | qwebchannel.cpp qwebchannel.h qwebchannel_p.h 28 | qwebchannelabstracttransport.cpp qwebchannelabstracttransport.h 29 | signalhandler_p.h 30 | qwebchannelglobal.h 31 | qwebchannel.js 32 | DEFINES 33 | QT_NO_CONTEXTLESS_CONNECT 34 | LIBRARIES 35 | Qt::CorePrivate 36 | EXTRA_CMAKE_FILES 37 | "${config_build_dir}/Qt6WebChannelExtras.cmake" 38 | EXTRA_CMAKE_INCLUDES 39 | Qt6WebChannelExtras.cmake 40 | ) 41 | 42 | qt_internal_add_resource(WebChannel "resources" 43 | PREFIX 44 | "/qtwebchannel/" 45 | FILES 46 | qwebchannel.js 47 | ) 48 | 49 | if(TARGET Qt::Qml) 50 | qt_internal_extend_target(WebChannel PUBLIC_LIBRARIES Qt::Qml) 51 | else() 52 | qt_internal_extend_target(WebChannel DEFINES QT_NO_JSVALUE) 53 | endif() 54 | 55 | qt_internal_add_docs(WebChannel 56 | doc/qtwebchannel.qdocconf 57 | ) 58 | 59 | install(FILES qwebchannel.js 60 | DESTINATION "${INSTALL_WEBCHANNEL_SHAREDIR}") 61 | file(COPY qwebchannel.js 62 | DESTINATION "${QT_BUILD_DIR}/${INSTALL_WEBCHANNEL_SHAREDIR}/") 63 | -------------------------------------------------------------------------------- /examples/webchannel/chatserver-cpp/doc/src/chatserver-cpp.qdoc: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2016 basysKom GmbH, author Bernd Lamecker 2 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GFDL-1.3-no-invariants-only 3 | 4 | /*! 5 | \example chatserver-cpp 6 | \title Qt WebChannel ChatServer Example 7 | \ingroup qtwebchannel-examples 8 | \examplecategory {Web Technologies} 9 | \brief A simple chat server implemented using the QWebChannel C++ API. 10 | 11 | \image chatserver-cpp.png 12 | 13 | \e{ChatServer} provides a chat service that the 14 | \l{Qt WebChannel ChatClient QML Application} and 15 | \l{Qt WebChannel ChatClient HTML Example} can connect to. 16 | 17 | \include examples-run.qdocinc 18 | 19 | \section1 Implementing a Chat Server 20 | 21 | The C++ application implements a QObject which provides all mechanisms required for 22 | a chat service. 23 | This object is published through a QWebChannel which uses a \l{Qt WebSockets} 24 | {WebSocket} as transport. 25 | 26 | The server provides a basic \c login method (username only, no passwords), which must be 27 | successfully invoked before a client is able to chat. 28 | After login, a client can invoke the method \c sendMessage and receive the signal \c newMessage 29 | to write and receive messages. Furthermore, there is a \c userList property which provides 30 | the names of all other connected clients. 31 | Additionally the server sends a \c keepAlive signal periodically to all clients. The clients 32 | have to respond to this signal, otherwise the client will be removed from the \c userList property. 33 | 34 | The example shows how basic QObject elements can be used with QWebChannel, that is signals 35 | (\c newMessage), slots (\c sendMessage), and properties (\c userList). 36 | 37 | Because this is a plain server application, separate clients are needed to 38 | interact with it. \l{Qt WebChannel ChatClient QML Application} and 39 | \l{Qt WebChannel ChatClient HTML Example} are client implementations 40 | compatible with this server. 41 | 42 | */ 43 | -------------------------------------------------------------------------------- /tests/auto/qml/testobject.cpp: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2017 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com, author Milian Wolff 2 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only 3 | 4 | #include "testobject.h" 5 | 6 | 7 | QT_BEGIN_NAMESPACE 8 | 9 | TestObject::TestObject(QObject* parent) 10 | : QObject(parent) 11 | , embeddedObject(new QObject(this)) 12 | { 13 | embeddedObject->setObjectName("embedded"); 14 | } 15 | 16 | TestObject::~TestObject() 17 | { 18 | } 19 | 20 | QVariantMap TestObject::objectMap() const 21 | { 22 | QVariantMap map; 23 | map.insert("subObject", QVariant::fromValue(embeddedObject)); 24 | return map; 25 | } 26 | 27 | QString TestObject::stringProperty() const 28 | { 29 | return m_stringProperty; 30 | } 31 | 32 | void TestObject::triggerSignals() 33 | { 34 | emit testSignalBool(true); 35 | emit testSignalBool(false); 36 | 37 | emit testSignalInt(42); 38 | emit testSignalInt(1); 39 | emit testSignalInt(0); 40 | } 41 | 42 | int TestObject::testOverload(int i) 43 | { 44 | emit testOverloadSignal(i); 45 | return i + 1; 46 | } 47 | 48 | QString TestObject::testOverload(const QString &str) 49 | { 50 | emit testOverloadSignal(str); 51 | return str.toUpper(); 52 | } 53 | 54 | QString TestObject::testOverload(const QString &str, int i) 55 | { 56 | emit testOverloadSignal(str, i); 57 | return str.toUpper() + QString::number(i + 1); 58 | } 59 | 60 | int TestObject::testVariantType(const QVariant &val) 61 | { 62 | return val.metaType().id(); 63 | } 64 | 65 | bool TestObject::testEmbeddedObjects(const QVariantList &list) 66 | { 67 | return list.size() == 2 && 68 | list[0].metaType().id() == QMetaType::QObjectStar && 69 | list[1].metaType().id() == QMetaType::QVariantMap && 70 | list[1].toMap()["obj"].metaType().id() == QMetaType::QObjectStar; 71 | } 72 | 73 | void TestObject::setStringProperty(const QString &stringProperty) 74 | { 75 | m_stringProperty = stringProperty; 76 | } 77 | 78 | QObject* TestObject::createQObject() { 79 | return new QObject(this); 80 | } 81 | 82 | QT_END_NAMESPACE 83 | -------------------------------------------------------------------------------- /src/webchannel/doc/src/index.qdoc: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2014 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com, author Milian Wolff 2 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GFDL-1.3-no-invariants-only 3 | 4 | /*! 5 | \page qtwebchannel-index.html 6 | \since 5.4 7 | \title Qt WebChannel 8 | \brief Bridges the gap between Qt applications and HTML/JavaScript. 9 | 10 | Qt WebChannel enables peer-to-peer communication between a server (QML/C++ 11 | application) and a client (HTML/JavaScript or QML application). It is 12 | supported out of the box by \l{Qt WebEngine}. In addition, it can work on 13 | all browsers that support \l{Qt WebSockets}{WebSockets}, enabling Qt 14 | WebChannel clients to run in any JavaScript environment (including QML). 15 | This requires implementing a custom transport based on Qt WebSockets. 16 | 17 | The module provides a JavaScript library for seamless integration of C++ and 18 | QML applications with HTML/JavaScript and QML clients. The clients must use 19 | the JavaScript library to access the serialized QObjects published by the 20 | host applications. 21 | 22 | \section1 Using the Module 23 | 24 | \section2 QML API 25 | 26 | \include {module-use.qdocinc} {using the qml api} {QtWebChannel} 27 | 28 | \section2 C++ API 29 | 30 | \include {module-use.qdocinc} {using the c++ api} 31 | 32 | \section3 Building with CMake 33 | 34 | \include {module-use.qdocinc} {building with cmake} {WebChannel} 35 | 36 | \section3 Building with qmake 37 | 38 | \include {module-use.qdocinc} {building_with_qmake} {webchannel} 39 | 40 | \section1 Examples 41 | 42 | \list 43 | \li \l {Qt WebChannel Examples} {Examples} 44 | \endlist 45 | 46 | \section1 Reference 47 | 48 | \list 49 | \li \l {Qt WebChannel JavaScript API} {JavaScript API} 50 | \li \l {Qt WebChannel C++ Classes} {C++ API} 51 | \li \l {Qt WebChannel QML Types} {QML API} 52 | \endlist 53 | 54 | \section1 Licenses 55 | 56 | Qt WebChannel is available under commercial licenses from 57 | \l{The Qt Company}. 58 | In addition, it is available under free software licenses. 59 | These free software licenses are 60 | \l{GNU Lesser General Public License, version 3}, or 61 | the \l{GNU General Public License, version 2}. 62 | See \l{Qt Licensing} for further details. 63 | */ 64 | -------------------------------------------------------------------------------- /src/webchannel/qwebchannel.h: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2016 The Qt Company Ltd. 2 | // Copyright (C) 2016 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com, author Milian Wolff 3 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only 4 | // Qt-Security score:significant reason:default 5 | 6 | #ifndef QWEBCHANNEL_H 7 | #define QWEBCHANNEL_H 8 | 9 | #include 10 | #include 11 | 12 | #include 13 | 14 | class tst_bench_QWebChannel; 15 | 16 | QT_BEGIN_NAMESPACE 17 | 18 | class QWebChannelPrivate; 19 | class QWebChannelAbstractTransport; 20 | 21 | class Q_WEBCHANNEL_EXPORT QWebChannel : public QObject 22 | { 23 | Q_OBJECT 24 | Q_DISABLE_COPY(QWebChannel) 25 | Q_PROPERTY(bool blockUpdates READ blockUpdates WRITE setBlockUpdates NOTIFY blockUpdatesChanged 26 | BINDABLE bindableBlockUpdates) 27 | Q_PROPERTY(int propertyUpdateInterval READ propertyUpdateInterval WRITE 28 | setPropertyUpdateInterval BINDABLE bindablePropertyUpdateInterval) 29 | public: 30 | explicit QWebChannel(QObject *parent = nullptr); 31 | ~QWebChannel(); 32 | 33 | void registerObjects(const QHash &objects); 34 | QHash registeredObjects() const; 35 | Q_INVOKABLE void registerObject(const QString &id, QObject *object); 36 | Q_INVOKABLE void deregisterObject(QObject *object); 37 | 38 | bool blockUpdates() const; 39 | void setBlockUpdates(bool block); 40 | QBindable bindableBlockUpdates(); 41 | 42 | int propertyUpdateInterval() const; 43 | void setPropertyUpdateInterval(int ms); 44 | QBindable bindablePropertyUpdateInterval(); 45 | 46 | Q_SIGNALS: 47 | void blockUpdatesChanged(bool block); 48 | 49 | public Q_SLOTS: 50 | void connectTo(QWebChannelAbstractTransport *transport); 51 | void disconnectFrom(QWebChannelAbstractTransport *transport); 52 | 53 | private: 54 | Q_DECLARE_PRIVATE(QWebChannel) 55 | QWebChannel(QWebChannelPrivate &dd, QObject *parent = nullptr); 56 | Q_PRIVATE_SLOT(d_func(), void _q_transportDestroyed(QObject*)) 57 | 58 | friend class QMetaObjectPublisher; 59 | friend class QQmlWebChannel; 60 | friend class TestWebChannel; 61 | friend class ::tst_bench_QWebChannel; 62 | }; 63 | 64 | QT_END_NAMESPACE 65 | 66 | #endif // QWEBCHANNEL_H 67 | 68 | -------------------------------------------------------------------------------- /examples/webchannel/shared/websockettransport.cpp: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2016 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com, author Milian Wolff 2 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause 3 | 4 | #include "websockettransport.h" 5 | 6 | #include 7 | #include 8 | #include 9 | #include 10 | 11 | /*! 12 | \brief QWebChannelAbstractSocket implementation that uses a QWebSocket internally. 13 | 14 | The transport delegates all messages received over the QWebSocket over its 15 | textMessageReceived signal. Analogously, all calls to sendTextMessage will 16 | be send over the QWebSocket to the remote client. 17 | */ 18 | 19 | /*! 20 | Construct the transport object and wrap the given socket. 21 | 22 | The socket is also set as the parent of the transport object. 23 | */ 24 | WebSocketTransport::WebSocketTransport(QWebSocket *socket) 25 | : QWebChannelAbstractTransport(socket) 26 | , m_socket(socket) 27 | { 28 | connect(socket, &QWebSocket::textMessageReceived, 29 | this, &WebSocketTransport::textMessageReceived); 30 | connect(socket, &QWebSocket::disconnected, 31 | this, &WebSocketTransport::deleteLater); 32 | } 33 | 34 | /*! 35 | Destroys the WebSocketTransport. 36 | */ 37 | WebSocketTransport::~WebSocketTransport() 38 | { 39 | m_socket->deleteLater(); 40 | } 41 | 42 | /*! 43 | Serialize the JSON message and send it as a text message via the WebSocket to the client. 44 | */ 45 | void WebSocketTransport::sendMessage(const QJsonObject &message) 46 | { 47 | QJsonDocument doc(message); 48 | m_socket->sendTextMessage(QString::fromUtf8(doc.toJson(QJsonDocument::Compact))); 49 | } 50 | 51 | /*! 52 | Deserialize the stringified JSON messageData and emit messageReceived. 53 | */ 54 | void WebSocketTransport::textMessageReceived(const QString &messageData) 55 | { 56 | QJsonParseError error; 57 | QJsonDocument message = QJsonDocument::fromJson(messageData.toUtf8(), &error); 58 | if (error.error) { 59 | qWarning() << "Failed to parse text message as JSON object:" << messageData 60 | << "Error is:" << error.errorString(); 61 | return; 62 | } else if (!message.isObject()) { 63 | qWarning() << "Received JSON message that is not an object: " << messageData; 64 | return; 65 | } 66 | emit messageReceived(message.object(), this); 67 | } 68 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ### Introduction 2 | 3 | The Qt WebChannel module offers Qt applications a seamless way to publish `QObjects` for interaction 4 | with HTML/JavaScript clients. These clients can either be inside local Qt `WebView`s or any other, 5 | potentially remote, client which supports JavaScript, as long as a communication channel such 6 | as WebSocket is available. 7 | 8 | Qt WebChannel uses introspection on the `QObject`s and sends this serialized data to the clients. 9 | There, with the help of a small JavaScript library, an object is created which simulates the API of 10 | the `QObject`. Any invokable methods, including slots, can be called as well as properties read and 11 | written. Additionally you can connect to signals and register JavaScript callbacks as handlers. 12 | 13 | ### Dependencies 14 | 15 | This module depends on Qt Core only. Optionally, an additional plugin for Qt Quick can be built, which 16 | makes it easy to use a `QWebChannel` from QML. Note that this module alone is not functional. It 17 | is being used in e.g. Qt WebKit to provide a seamless integration of QML/C++ QObjects into JavaScript 18 | clients. You can integrate it in your projects as well, by providing an implementation of the 19 | `QWebChannelAbstractTransport` class, see the `standalone` example for how to do this. 20 | 21 | ### Building 22 | 23 | qmake-qt5 24 | make 25 | make install 26 | 27 | ### Usage from C++ 28 | 29 | To use the Qt/C++ library, add the following to your `QMake` project: 30 | 31 | QT += webchannel 32 | 33 | Then, in your C++ code, construct a webchannel, then publish your `QObject`s: 34 | 35 | QWebChannel channel; 36 | channel.registerObject(QStringLiteral("foo"), myFooObj); 37 | .... 38 | 39 | Additionally, you need to provide a communication channel to the HTML client. One way is to 40 | use the Qt WebSockets module. On the HTML/JavaScript client side, you need to embed 41 | `src/webchannel/qwebchannel.js` and setup the connection to a client-side transport. An example 42 | which shows all this in action can be found in `examples/standalone`. 43 | 44 | ### Usage from Qt Quick 45 | 46 | For QML applications, use the following import: 47 | 48 | import QtWebChannel 1.0 49 | 50 | Then setup the WebChannel, register objects to it and connect to transport objects: 51 | 52 | WebChannel { 53 | registeredObjects: [foo, bar, ...] 54 | 55 | transports: [yourTransport] 56 | } 57 | 58 | To see this in action, take a look at the test code in `tests/auto/qml`. 59 | -------------------------------------------------------------------------------- /tests/auto/qml/data/tst_bench.qml: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2016 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com, author Milian Wolff 2 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only 3 | 4 | import QtQuick 5 | import QtTest 6 | 7 | import QtWebChannel 8 | import QtWebChannel.Tests 9 | 10 | TestCase { 11 | name: "Bench" 12 | id: test 13 | 14 | Client { 15 | id: client 16 | } 17 | 18 | TestWebChannel { 19 | id: webChannel 20 | transports: [client.serverTransport] 21 | } 22 | 23 | Component { 24 | id: component 25 | QtObject { 26 | property var p0 : 0 27 | property var p1 : 0 28 | property var p2 : 0 29 | property var p3 : 0 30 | property var p4 : 0 31 | property var p5 : 0 32 | property var p6 : 0 33 | property var p7 : 0 34 | property var p8 : 0 35 | property var p9 : 0 36 | function m0(arg1, arg2) {} 37 | function m1(arg1, arg2) {} 38 | function m2(arg1, arg2) {} 39 | function m3(arg1, arg2) {} 40 | function m4(arg1, arg2) {} 41 | function m5(arg1, arg2) {} 42 | function m6(arg1, arg2) {} 43 | function m7(arg1, arg2) {} 44 | function m8(arg1, arg2) {} 45 | function m9(arg1, arg2) {} 46 | signal s0(var arg1, var arg2) 47 | signal s1(var arg1, var arg2) 48 | signal s2(var arg1, var arg2) 49 | signal s3(var arg1, var arg2) 50 | signal s4(var arg1, var arg2) 51 | signal s5(var arg1, var arg2) 52 | signal s6(var arg1, var arg2) 53 | signal s7(var arg1, var arg2) 54 | signal s8(var arg1, var arg2) 55 | signal s9(var arg1, var arg2) 56 | } 57 | } 58 | 59 | property var objects: ({}) 60 | 61 | function initTestCase() 62 | { 63 | for (var i = 0; i < 100; ++i) { 64 | var id = "obj" + i; 65 | var properties = {objectName: id}; 66 | objects[id] = component.createObject(test, properties); 67 | } 68 | 69 | webChannel.registerObjects(objects); 70 | } 71 | 72 | function cleanup() 73 | { 74 | client.cleanup(); 75 | } 76 | 77 | function benchmark_init() 78 | { 79 | var channel = client.createChannel(function() {}); 80 | client.awaitInit(); 81 | client.awaitIdle(); 82 | } 83 | } 84 | -------------------------------------------------------------------------------- /src/webchannelquick/qqmlwebchannel.h: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2016 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com, author 2 | // Milian Wolff 3 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only 4 | // Qt-Security score:significant reason:default 5 | 6 | #ifndef QQMLWEBCHANNEL_H 7 | #define QQMLWEBCHANNEL_H 8 | 9 | #include 10 | #include 11 | 12 | #include 13 | #include 14 | 15 | QT_BEGIN_NAMESPACE 16 | 17 | class QQmlWebChannelPrivate; 18 | class QQmlWebChannelAttached; 19 | class Q_WEBCHANNELQUICK_EXPORT QQmlWebChannel : public QWebChannel 20 | { 21 | Q_OBJECT 22 | Q_DISABLE_COPY(QQmlWebChannel) 23 | 24 | Q_PROPERTY(QQmlListProperty transports READ transports) 25 | Q_PROPERTY(QQmlListProperty registeredObjects READ registeredObjects) 26 | QML_NAMED_ELEMENT(WebChannel) 27 | QML_ATTACHED(QQmlWebChannelAttached) 28 | QML_ADDED_IN_VERSION(1, 0) 29 | public: 30 | explicit QQmlWebChannel(QObject *parent = nullptr); 31 | virtual ~QQmlWebChannel(); 32 | 33 | Q_INVOKABLE void registerObjects(const QVariantMap &objects); 34 | QQmlListProperty registeredObjects(); 35 | 36 | QQmlListProperty transports(); 37 | 38 | static QQmlWebChannelAttached *qmlAttachedProperties(QObject *obj); 39 | 40 | Q_INVOKABLE void connectTo(QObject *transport); 41 | Q_INVOKABLE void disconnectFrom(QObject *transport); 42 | 43 | private: 44 | Q_DECLARE_PRIVATE(QQmlWebChannel) 45 | Q_PRIVATE_SLOT(d_func(), void _q_objectIdChanged(const QString &newId)) 46 | 47 | static void registeredObjects_append(QQmlListProperty *prop, QObject *item); 48 | static qsizetype registeredObjects_count(QQmlListProperty *prop); 49 | static QObject *registeredObjects_at(QQmlListProperty *prop, qsizetype index); 50 | static void registeredObjects_clear(QQmlListProperty *prop); 51 | 52 | static void transports_append(QQmlListProperty *prop, QObject *item); 53 | static qsizetype transports_count(QQmlListProperty *prop); 54 | static QObject *transports_at(QQmlListProperty *prop, qsizetype index); 55 | static void transports_clear(QQmlListProperty *prop); 56 | }; 57 | 58 | QT_END_NAMESPACE 59 | 60 | QML_DECLARE_TYPE(QQmlWebChannel) 61 | QML_DECLARE_TYPEINFO(QQmlWebChannel, QML_HAS_ATTACHED_PROPERTIES) 62 | 63 | #endif // QQMLWEBCHANNEL_H 64 | -------------------------------------------------------------------------------- /examples/webchannel/chatserver-cpp/chatserver.cpp: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2016 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com, author Milian Wolff 2 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause 3 | 4 | #include "chatserver.h" 5 | 6 | #include 7 | #include 8 | #include 9 | 10 | ChatServer::ChatServer(QObject *parent) 11 | : QObject(parent) 12 | { 13 | QTimer *t = new QTimer(this); 14 | connect(t, &QTimer::timeout, this, &ChatServer::sendKeepAlive); 15 | t->start(10000); 16 | 17 | m_keepAliveCheckTimer = new QTimer(this); 18 | m_keepAliveCheckTimer->setSingleShot(true); 19 | m_keepAliveCheckTimer->setInterval(2000); 20 | connect(m_keepAliveCheckTimer, &QTimer::timeout, this, &ChatServer::checkKeepAliveResponses); 21 | } 22 | 23 | ChatServer::~ChatServer() 24 | {} 25 | 26 | 27 | bool ChatServer::login(const QString &userName) 28 | { 29 | //stop keepAliveCheck, when a new user logged in 30 | if (m_keepAliveCheckTimer->isActive()) { 31 | m_keepAliveCheckTimer->stop(); 32 | m_stillAliveUsers.clear(); 33 | } 34 | 35 | if (m_userList.contains(userName)) { 36 | return false; 37 | } 38 | 39 | qDebug() << "User logged in:" << userName; 40 | m_userList.append(userName); 41 | m_userList.sort(); 42 | emit userListChanged(); 43 | emit userCountChanged(); 44 | return true; 45 | } 46 | 47 | bool ChatServer::logout(const QString &userName) 48 | { 49 | if (!m_userList.contains(userName)) { 50 | return false; 51 | } else { 52 | m_userList.removeAt(m_userList.indexOf(userName)); 53 | emit userListChanged(); 54 | emit userCountChanged(); 55 | return true; 56 | } 57 | } 58 | 59 | bool ChatServer::sendMessage(const QString &user, const QString &msg) 60 | { 61 | if (m_userList.contains(user)) { 62 | emit newMessage(QTime::currentTime().toString("HH:mm:ss"), user, msg); 63 | return true; 64 | } else { 65 | return false; 66 | } 67 | } 68 | 69 | void ChatServer::sendKeepAlive() 70 | { 71 | emit keepAlive(); 72 | m_keepAliveCheckTimer->start(); 73 | } 74 | 75 | void ChatServer::checkKeepAliveResponses() 76 | { 77 | qDebug() << "Keep Alive Check" << m_stillAliveUsers; 78 | m_userList = m_stillAliveUsers; 79 | m_stillAliveUsers.clear(); 80 | m_userList.sort(); 81 | emit userListChanged(); 82 | } 83 | 84 | void ChatServer::keepAliveResponse(const QString &user) 85 | { 86 | m_stillAliveUsers.append(user); 87 | } 88 | 89 | 90 | QStringList ChatServer::userList() const 91 | { 92 | return m_userList; 93 | } 94 | -------------------------------------------------------------------------------- /examples/webchannel/chatclient-qml/doc/src/chatclient-qml.qdoc: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2016 basysKom GmbH, author Bernd Lamecker 2 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GFDL-1.3-no-invariants-only 3 | 4 | /*! 5 | \example chatclient-qml 6 | \title Qt WebChannel ChatClient QML Application 7 | \ingroup qtwebchannel-examples 8 | \brief A QML client that communicates over a WebSocket with a QWebChannel server. 9 | \examplecategory {Web Technologies} 10 | \meta tag {rpc,network} 11 | 12 | \image chatclient-qml.png 13 | 14 | \e{ChatClient QML} provides a simple QWebChannel client implemented using JavaScript and QML. 15 | 16 | \section1 Implementing a Web Channel Client in QML 17 | 18 | This example shows how you can use the basic elements with the client JavaScript 19 | implementation of QWebChannel, like connecting to signals (\c newMessage), 20 | calling slots (\c sendMessage), and handling property changes (\c userList). 21 | 22 | The client initializes a \l [QML] WebSocket connection to the chat server at port 23 | 12345 on localhost. When the WebSocket opens, a WebChannel object is created, taking 24 | the WebSocket as first argument and a callback function as the second argument. When 25 | the callback is called, the client receives an object named \c chatserver, 26 | containing all the necessary signals, slots, and properties for implementing a chat 27 | client. The callback function connects \c userListChanged, \c newMessage, and 28 | \c keepAlive on the \c chatserver object with separate functions handling those 29 | signals, and then it calls \c show on \c loginWindow. 30 | 31 | The \c Window with \c loginWindow as id handles the login procedure. It contains a 32 | \c LoginForm defined in LoginForm.ui.qml. When you press the button, it calls 33 | the \c login function on the \c chatserver object with the login name and and a 34 | callback function as arguments. This callback function handles both if the login 35 | succeeds or fails. 36 | 37 | After login, the client uses a \c MainForm, defined in MainForm.ui.qml, with 38 | \c mainUi as id, to post messages using the \c sendMessage slot, read messages 39 | using the \c newMessage signal, and to view the names of all connected users 40 | using the \c userList property. Also, the client responds to the server's 41 | \c keepAlive signal in order for the server to detect disconnected clients 42 | and remove them from the \c userList property. 43 | 44 | The client is able to work with the \l{Qt WebChannel ChatServer Example}. 45 | 46 | \sa {Qt WebChannel ChatServer Example}, {Qt WebChannel ChatClient HTML Example} 47 | 48 | */ 49 | -------------------------------------------------------------------------------- /src/webchannel/doc/qtwebchannel.qdocconf: -------------------------------------------------------------------------------- 1 | include($QT_INSTALL_DOCS/global/qt-module-defaults.qdocconf) 2 | include($QT_INSTALL_DOCS/config/exampleurl-qtwebchannel.qdocconf) 3 | 4 | project = QtWebChannel 5 | description = Qt WebChannel Reference Documentation 6 | version = $QT_VERSION 7 | 8 | examplesinstallpath = webchannel 9 | 10 | # Path to the root of qtwebchannel (for automatic linking to source code) 11 | url.sources.rootdir = ../../.. 12 | 13 | qhp.projects = QtWebChannel 14 | 15 | qhp.QtWebChannel.file = qtwebchannel.qhp 16 | qhp.QtWebChannel.namespace = org.qt-project.qtwebchannel.$QT_VERSION_TAG 17 | qhp.QtWebChannel.virtualFolder = qtwebchannel 18 | qhp.QtWebChannel.indexTitle = Qt WebChannel 19 | qhp.QtWebChannel.indexRoot = 20 | 21 | qhp.QtWebChannel.subprojects = classes qml examples javascript 22 | 23 | qhp.QtWebChannel.subprojects.classes.title = C++ Classes 24 | qhp.QtWebChannel.subprojects.classes.indexTitle = Qt WebChannel C++ Classes 25 | qhp.QtWebChannel.subprojects.classes.selectors = class headerfile 26 | qhp.QtWebChannel.subprojects.classes.sortPages = true 27 | 28 | qhp.QtWebChannel.subprojects.qml.title = QML Types 29 | qhp.QtWebChannel.subprojects.qml.indexTitle = Qt WebChannel QML Types 30 | qhp.QtWebChannel.subprojects.qml.selectors = qmltype 31 | qhp.QtWebChannel.subprojects.qml.sortPages = true 32 | 33 | qhp.QtWebChannel.subprojects.examples.title = Examples 34 | qhp.QtWebChannel.subprojects.examples.indexTitle = Qt WebChannel Examples 35 | qhp.QtWebChannel.subprojects.examples.selectors = doc:example 36 | qhp.QtWebChannel.subprojects.examples.sortPages = true 37 | 38 | qhp.QtWebChannel.subprojects.javascript.title = JavaScript API 39 | qhp.QtWebChannel.subprojects.javascript.indexTitle = Qt WebChannel JavaScript API 40 | 41 | tagfile = ../../../doc/qtwebchannel/qtwebchannel.tags 42 | 43 | depends += qtcore qtquick qtqml qtdoc qtwebengine qtwebsockets qmake qtcmake 44 | 45 | headerdirs += .. \ 46 | ../../webchannelquick 47 | 48 | sourcedirs += .. \ 49 | ../../webchannelquick 50 | 51 | imagedirs += images 52 | 53 | exampledirs += ../../../examples/webchannel 54 | examples.fileextensions += "*.html *.json" 55 | 56 | navigation.landingpage = "Qt WebChannel" 57 | navigation.cppclassespage = "Qt WebChannel C++ Classes" 58 | navigation.qmltypespage = "Qt WebChannel QML Types" 59 | 60 | manifestmeta.highlighted.names = "QtWebChannel/Qt WebChannel Standalone Example" 61 | -------------------------------------------------------------------------------- /examples/webchannel/standalone/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 56 | 74 | 75 | 76 |
77 | 78 | 79 | 80 | -------------------------------------------------------------------------------- /tests/benchmarks/webchannel/tst_bench_qwebchannel.h: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2016 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com, author Milian Wolff 2 | // Copyright (C) 2019 Menlo Systems GmbH, author Arno Rehn 3 | // Copyright (C) 2023 The Qt Company Ltd. 4 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only 5 | 6 | #ifndef TST_BENCH_QWEBCHANNEL_H 7 | #define TST_BENCH_QWEBCHANNEL_H 8 | 9 | #include 10 | #include 11 | 12 | QT_USE_NAMESPACE 13 | 14 | class DummyTransport : public QWebChannelAbstractTransport 15 | { 16 | Q_OBJECT 17 | public: 18 | explicit DummyTransport(QObject *parent = nullptr) 19 | : QWebChannelAbstractTransport(parent) 20 | {} 21 | ~DummyTransport() {}; 22 | 23 | public slots: 24 | void sendMessage(const QJsonObject &message) override 25 | { 26 | Q_UNUSED(message); 27 | } 28 | }; 29 | 30 | class BenchObject : public QObject 31 | { 32 | Q_OBJECT 33 | 34 | Q_PROPERTY(int p0 MEMBER m_p0 NOTIFY p0Changed) 35 | Q_PROPERTY(int p1 MEMBER m_p1 NOTIFY p1Changed) 36 | Q_PROPERTY(int p2 MEMBER m_p2 NOTIFY p2Changed) 37 | Q_PROPERTY(int p3 MEMBER m_p3 NOTIFY p3Changed) 38 | Q_PROPERTY(int p4 MEMBER m_p4 NOTIFY p4Changed) 39 | Q_PROPERTY(int p5 MEMBER m_p5 NOTIFY p5Changed) 40 | Q_PROPERTY(int p6 MEMBER m_p6 NOTIFY p6Changed) 41 | Q_PROPERTY(int p7 MEMBER m_p7 NOTIFY p7Changed) 42 | Q_PROPERTY(int p8 MEMBER m_p8 NOTIFY p8Changed) 43 | Q_PROPERTY(int p9 MEMBER m_p9 NOTIFY p9Changed) 44 | public: 45 | explicit BenchObject(QObject *parent = 0) 46 | : QObject(parent) 47 | , m_p0(0) 48 | , m_p1(0) 49 | , m_p2(0) 50 | , m_p3(0) 51 | , m_p4(0) 52 | , m_p5(0) 53 | , m_p6(0) 54 | , m_p7(0) 55 | , m_p8(0) 56 | , m_p9(0) 57 | { } 58 | 59 | void change() 60 | { 61 | m_p0++; 62 | m_p1++; 63 | m_p2++; 64 | m_p3++; 65 | m_p4++; 66 | m_p5++; 67 | m_p6++; 68 | m_p7++; 69 | m_p8++; 70 | m_p9++; 71 | emit p0Changed(m_p0); 72 | emit p1Changed(m_p1); 73 | emit p2Changed(m_p2); 74 | emit p3Changed(m_p3); 75 | emit p4Changed(m_p4); 76 | emit p5Changed(m_p5); 77 | emit p6Changed(m_p6); 78 | emit p7Changed(m_p7); 79 | emit p8Changed(m_p8); 80 | emit p9Changed(m_p9); 81 | } 82 | 83 | signals: 84 | void s0(); 85 | void s1(); 86 | void s2(); 87 | void s3(); 88 | void s4(); 89 | void s5(); 90 | void s6(); 91 | void s7(); 92 | void s8(); 93 | void s9(); 94 | 95 | void p0Changed(int); 96 | void p1Changed(int); 97 | void p2Changed(int); 98 | void p3Changed(int); 99 | void p4Changed(int); 100 | void p5Changed(int); 101 | void p6Changed(int); 102 | void p7Changed(int); 103 | void p8Changed(int); 104 | void p9Changed(int); 105 | 106 | public slots: 107 | void m0(){}; 108 | void m1(){}; 109 | void m2(){}; 110 | void m3(){}; 111 | void m4(){}; 112 | void m5(){}; 113 | void m6(){}; 114 | void m7(){}; 115 | void m8(){}; 116 | void m9(){}; 117 | 118 | private: 119 | int m_p0, m_p1, m_p2, m_p3, m_p4, m_p5, m_p6, m_p7, m_p8, m_p9; 120 | }; 121 | 122 | #endif // TST_BENCH_QWEBCHANNEL_H 123 | -------------------------------------------------------------------------------- /examples/webchannel/nodejs/chatclient.js: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2016 The Qt Company Ltd. 2 | // Copyright (C) 2016 basysKom GmbH, author Bernd Lamecker 3 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause 4 | 'use strict'; 5 | 6 | var readline = require('readline'); 7 | var QWebChannel = require('./qwebchannel.js').QWebChannel; 8 | var websocket = require('faye-websocket'); 9 | 10 | var address = 'ws://127.0.0.1:12345'; 11 | var socket = new websocket.Client(address); 12 | 13 | console.log('Chat client connecting to ' + address + ' (Ctrl-D to quit)'); 14 | 15 | var createReadlineInterface = function() { 16 | var bye = function() { 17 | console.log('Bye...'); 18 | process.exit(0); 19 | } 20 | 21 | var rlif = readline.createInterface({ 22 | input: process.stdin, 23 | output: process.stdout 24 | }); 25 | rlif.setPrompt('chat: '); 26 | 27 | // Handle Ctrl-D and Ctrl-C 28 | rlif.on('close', bye); 29 | rlif.on('SIGINT', bye); 30 | 31 | return rlif; 32 | } 33 | 34 | var createWebChannel = function(transport, rlif) { 35 | return new QWebChannel(transport, function(channel) { 36 | // We connect to the 'sendText' signal of the remote QObject 37 | // Be aware, that the signal is named for the remote side, 38 | // i.e. the server wants to 'send text'. 39 | // This can be confusing, as we connect to the signal 40 | // to receive incoming messages on our side 41 | channel.objects.core.sendText.connect(function(message) { 42 | process.stdout.cursorTo(0); 43 | process.stdout.clearLine(0); 44 | console.log(' << ' + message); 45 | rlif.prompt(); 46 | // Go to end of existing input if any 47 | rlif.write(null, { 48 | ctrl: true, 49 | name: 'e' 50 | }) 51 | }); 52 | 53 | rlif.on('line', function(line) { 54 | var l = line.trim(); 55 | if (l !== '') { 56 | process.stdout.moveCursor(0, -1); 57 | process.stdout.cursorTo(0); 58 | process.stdout.clearLine(0); 59 | // The 'receiveText' slot of the remote QObject 60 | // is called with our message. 61 | // Again the naming is for the server side, 62 | // i.e. the slot is used _by the server_ to receive text. 63 | channel.objects.core.receiveText(l); 64 | console.log(' >> ' + l); 65 | } 66 | rlif.prompt(); 67 | }); 68 | rlif.prompt(); 69 | }); 70 | } 71 | 72 | socket.on('open', function(event) { 73 | console.log("info: Client connected"); 74 | var transport = { 75 | // We cant't do 'send: socket.send' here 76 | // because 'send' wouldn't be bound to 'socket' 77 | send: function(data) { 78 | socket.send(data) 79 | } 80 | }; 81 | 82 | createWebChannel(transport, createReadlineInterface()); 83 | 84 | // QWebChannel has set up its onmessage handler 85 | // on the transport in the constructor. 86 | // Now we connect it to the websocket event. 87 | socket.on('message', function(event) { 88 | transport.onmessage(event); 89 | }); 90 | }); 91 | 92 | socket.on('error', function(error) { 93 | console.log('Connection error: ' + error.message); 94 | process.exit(1); 95 | }); 96 | 97 | socket.on('close', function() { 98 | console.log('Connection closed.'); 99 | process.exit(1); 100 | }); 101 | -------------------------------------------------------------------------------- /examples/webchannel/qwclient/qwclient.js: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env node 2 | // Copyright (C) 2016 basysKom GmbH, author Sumedha Widyadharma 3 | // Copyright (C) 2016 basysKom GmbH, author Lutz Schönemann 4 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause 5 | 6 | 'use strict'; 7 | var repl = require('repl'); 8 | var WebSocket = require('faye-websocket').Client; 9 | var QWebChannel = new require('./qwebchannel.js').QWebChannel; 10 | 11 | var serverAddress = 'ws://localhost:12345'; 12 | var channels = []; 13 | 14 | var autoConnect = process.argv.pop(); 15 | if (autoConnect === __filename) { 16 | autoConnect = false; 17 | } 18 | 19 | var openChannel = function(address) { 20 | // this should be bound to the repl 21 | var self = this; 22 | address = address ? address : serverAddress; 23 | if (address.indexOf('://') === -1) { 24 | address = 'ws://' + address; 25 | } 26 | 27 | var ws = new WebSocket(address); 28 | 29 | ws.on('open', function(event) { 30 | var transport = { 31 | onmessage: function(data) {}, 32 | send: function(data) { 33 | ws.send(data, { 34 | binary: false 35 | }); 36 | } 37 | }; 38 | ws.on('message', function(event) { 39 | transport.onmessage(event); 40 | }); // onmessage 41 | 42 | var webChannel = new QWebChannel(transport, function(channel) { 43 | channels.push(channel); 44 | var channelIdx = (channels.length - 1); 45 | console.log('channel opened', channelIdx); 46 | // Create a nice alias to access this channels objects 47 | self.context['c' + channelIdx] = channel.objects; 48 | 49 | ws.on('close', function() { 50 | for (var i = 0; i < channels.length; ++i) { 51 | if (channels[i] === channel) { 52 | console.log('channel closed', i); 53 | channels[i] = null; 54 | return; 55 | } 56 | } 57 | }); // onclose 58 | }); // new QWebChannel 59 | }); // onopen 60 | 61 | ws.on('error', function(error) { 62 | console.log('websocket error', error.message); 63 | }); 64 | }; // openChannel 65 | 66 | var setupRepl = function() { 67 | var r = repl.start({ 68 | prompt: "webchannel> ", 69 | input: process.stdin, 70 | output: process.stdout, 71 | ignoreUndefined: true 72 | }); 73 | 74 | r.context.serverAddress = serverAddress; 75 | r.context.openChannel = openChannel.bind(r); 76 | r.context.channels = channels; 77 | 78 | r.context.lsObjects = function() { 79 | for (let i = 0; i < channels.length; ++i) { 80 | const channel = channels[i]; 81 | if (!channel) // closed and removed channel in repl 82 | continue; 83 | 84 | console.log('-- Channel "c' + i + '" objects:'); 85 | for (const obj of Object.keys(channel.objects)) 86 | console.log(obj, ':', channel.objects[obj]); 87 | } 88 | } 89 | return r; 90 | } 91 | 92 | var welcome = function() { 93 | console.log('Welcome to the qwebchannel/websocket REPL.'); 94 | console.log('Use openChannel(url) to connect to a service.'); 95 | console.log('For the standalone example, just openChannel() should suffice.'); 96 | console.log('Opened channels have their objects aliased to c, i.e. c0'); 97 | console.log('So for the standalone example try: c0.core.receiveText(\'hello world\')'); 98 | } 99 | 100 | welcome(); 101 | var repl = setupRepl(); 102 | 103 | if (autoConnect) { 104 | repl.context.openChannel(autoConnect); 105 | } 106 | -------------------------------------------------------------------------------- /tests/benchmarks/webchannel/tst_bench_qwebchannel.cpp: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2016 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com, author Milian Wolff 2 | // Copyright (C) 2019 Menlo Systems GmbH, author Arno Rehn 3 | // Copyright (C) 2023 The Qt Company Ltd. 4 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only 5 | 6 | #include "tst_bench_qwebchannel.h" 7 | 8 | #include 9 | 10 | #include 11 | 12 | #include 13 | #include 14 | 15 | class tst_bench_QWebChannel : public QObject 16 | { 17 | Q_OBJECT 18 | public: 19 | tst_bench_QWebChannel(QObject *parent = nullptr); 20 | 21 | private slots: 22 | void benchClassInfo(); 23 | void benchInitializeClients(); 24 | void benchPropertyUpdates(); 25 | void benchRegisterObjects(); 26 | void benchRemoveTransport(); 27 | 28 | private: 29 | DummyTransport *m_dummyTransport; 30 | }; 31 | 32 | tst_bench_QWebChannel::tst_bench_QWebChannel(QObject *parent) 33 | : QObject(parent), 34 | m_dummyTransport(new DummyTransport(this)) 35 | { 36 | } 37 | 38 | static QHash createObjects(QObject *parent) 39 | { 40 | const int num = 100; 41 | QHash objects; 42 | objects.reserve(num); 43 | for (int i = 0; i < num; ++i) { 44 | objects[QStringLiteral("obj%1").arg(i)] = new BenchObject(parent); 45 | } 46 | return objects; 47 | } 48 | 49 | void tst_bench_QWebChannel::benchClassInfo() 50 | { 51 | QWebChannel channel; 52 | channel.connectTo(m_dummyTransport); 53 | 54 | QObject parent; 55 | const QHash objects = createObjects(&parent); 56 | QMetaObjectPublisher *publisher = channel.d_func()->publisher; 57 | 58 | QBENCHMARK { 59 | for (const QObject *object : objects) 60 | publisher->classInfoForObject(object, m_dummyTransport); 61 | } 62 | } 63 | 64 | void tst_bench_QWebChannel::benchInitializeClients() 65 | { 66 | QWebChannel channel; 67 | channel.connectTo(m_dummyTransport); 68 | 69 | QObject parent; 70 | channel.registerObjects(createObjects(&parent)); 71 | 72 | QMetaObjectPublisher *publisher = channel.d_func()->publisher; 73 | QBENCHMARK { 74 | publisher->initializeClient(m_dummyTransport); 75 | 76 | publisher->propertyUpdatesInitialized = false; 77 | publisher->signalToPropertyMap.clear(); 78 | publisher->signalHandlers.clear(); 79 | } 80 | } 81 | 82 | void tst_bench_QWebChannel::benchPropertyUpdates() 83 | { 84 | QWebChannel channel; 85 | channel.connectTo(m_dummyTransport); 86 | 87 | QObject parent; 88 | const QHash objects = createObjects(&parent); 89 | QList objectList; 90 | objectList.reserve(objects.size()); 91 | for (QObject *obj : objects) 92 | objectList << qobject_cast(obj); 93 | 94 | channel.registerObjects(objects); 95 | channel.d_func()->publisher->initializeClient(m_dummyTransport); 96 | 97 | QBENCHMARK { 98 | for (BenchObject *obj : std::as_const(objectList)) 99 | obj->change(); 100 | 101 | channel.d_func()->publisher->setClientIsIdle(true, m_dummyTransport); 102 | channel.d_func()->publisher->sendPendingPropertyUpdates(); 103 | } 104 | } 105 | 106 | void tst_bench_QWebChannel::benchRegisterObjects() 107 | { 108 | QWebChannel channel; 109 | channel.connectTo(m_dummyTransport); 110 | 111 | QObject parent; 112 | const QHash objects = createObjects(&parent); 113 | 114 | QBENCHMARK { 115 | channel.registerObjects(objects); 116 | } 117 | } 118 | 119 | void tst_bench_QWebChannel::benchRemoveTransport() 120 | { 121 | QWebChannel channel; 122 | std::vector> dummyTransports(500); 123 | for (auto &e : dummyTransports) 124 | e = std::make_unique(this); 125 | 126 | std::vector> objs; 127 | QMetaObjectPublisher *pub = channel.d_func()->publisher; 128 | 129 | for (auto &e : dummyTransports) { 130 | DummyTransport *transport = e.get(); 131 | channel.connectTo(transport); 132 | channel.d_func()->publisher->initializeClient(transport); 133 | 134 | /* 30 objects per transport */ 135 | for (int i = 30; i > 0; i--) { 136 | auto obj = std::make_unique(); 137 | pub->wrapResult(QVariant::fromValue(obj.get()), transport); 138 | objs.push_back(std::move(obj)); 139 | } 140 | } 141 | 142 | QBENCHMARK_ONCE { 143 | for (auto &transport : dummyTransports) 144 | pub->transportRemoved(transport.get()); 145 | } 146 | } 147 | 148 | QTEST_MAIN(tst_bench_QWebChannel) 149 | 150 | #include "tst_bench_qwebchannel.moc" 151 | -------------------------------------------------------------------------------- /tests/auto/qml/data/Client.qml: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2016 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com, author Milian Wolff 2 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only 3 | 4 | import QtQuick 5 | import QtTest 6 | 7 | import QtWebChannel 8 | import QtWebChannel.Tests 9 | import "qrc:///qtwebchannel/qwebchannel.js" as JSClient 10 | 11 | Item { 12 | id: root 13 | 14 | TestTransport { 15 | id: serverTransport 16 | } 17 | readonly property var serverTransport: serverTransport 18 | 19 | property var clientMessages: [] 20 | property var serverMessages: [] 21 | 22 | property bool debug: false 23 | 24 | QtObject { 25 | id: clientTransport 26 | 27 | property var onmessage; 28 | 29 | function send(message) 30 | { 31 | if (debug) 32 | console.log("client", (root.objectName ? "(" + root.objectName + ")" : ""), "posts message: ", message, "is idle:", webChannel.clientIsIdle()); 33 | clientMessages.push(JSON.parse(message)); 34 | serverTransport.receiveMessage(message); 35 | if (message && message.type && message.type === JSClient.QWebChannelMessageTypes.idle) 36 | verify(webChannel.clientIsIdle()); 37 | } 38 | 39 | Component.onCompleted: { 40 | serverTransport.sendMessageRequested.connect(function receive(message) { 41 | if (debug) 42 | console.log("client", (root.objectName ? "(" + root.objectName + ")" : ""), "received message:", JSON.stringify(message)); 43 | serverMessages.push(message); 44 | if (onmessage) 45 | onmessage({data:message}); 46 | }); 47 | } 48 | } 49 | readonly property var clientTransport: clientTransport 50 | 51 | function createChannel(callback, raw) 52 | { 53 | return new JSClient.QWebChannel(clientTransport, callback, raw); 54 | } 55 | 56 | function cleanup() 57 | { 58 | clientMessages = []; 59 | serverMessages = []; 60 | } 61 | 62 | function awaitRawMessage(from) 63 | { 64 | var messages; 65 | if (!from || typeof from !== "string" || from == "client") { 66 | from = "client"; 67 | messages = clientMessages; 68 | } else { 69 | from = "server"; 70 | messages = serverMessages; 71 | } 72 | 73 | for (var i = 0; i < 10 && !messages.length; ++i) 74 | wait(10); 75 | 76 | var msg = messages.shift(); 77 | if (debug) { 78 | console.log((root.objectName ? "(" + root.objectName + ")" : ""), "shifting message " + from + "[" + messages.length + "]" + ":" + JSON.stringify(msg)); 79 | } 80 | return msg; 81 | } 82 | 83 | function awaitMessage(from) 84 | { 85 | var msg = awaitRawMessage(from) 86 | if (debug) 87 | console.log((root.objectName ? "(" + root.objectName + ")" : ""), "handling message: ", JSON.stringify(msg)); 88 | if (!msg) 89 | return false; 90 | return msg; 91 | } 92 | 93 | function await(type, from, skip) { 94 | var msg; 95 | do { 96 | msg = awaitMessage(from); 97 | if (!msg) { 98 | console.trace(); 99 | verify(msg); 100 | } 101 | } while (skip && (msg.type === JSClient.QWebChannelMessageTypes.idle)); 102 | if (type !== null) { 103 | if (!msg || msg.type != type) 104 | console.trace(); 105 | verify(msg); 106 | compare(msg.type, type); 107 | } 108 | return msg; 109 | } 110 | 111 | function awaitInit() { 112 | return await(JSClient.QWebChannelMessageTypes.init); 113 | } 114 | 115 | function awaitIdle() { 116 | return await(JSClient.QWebChannelMessageTypes.idle); 117 | } 118 | 119 | function awaitMessageSkipIdle() { 120 | return awaitFunc(null, null, true); 121 | } 122 | 123 | function awaitServerInit() { 124 | return await(JSClient.QWebChannelMessageTypes.init, "server"); 125 | } 126 | 127 | function awaitSignal() 128 | { 129 | return await(JSClient.QWebChannelMessageTypes.signal, "server"); 130 | } 131 | 132 | function awaitPropertyUpdate() 133 | { 134 | return await(JSClient.QWebChannelMessageTypes.propertyUpdate, "server"); 135 | } 136 | 137 | function awaitResponse() 138 | { 139 | return await(JSClient.QWebChannelMessageTypes.response, "server"); 140 | } 141 | 142 | function skipToMessage(type, from, max) { 143 | do { 144 | var msg = awaitMessage(from); 145 | if (msg && msg.type === type) 146 | return msg 147 | } while (--max > 0); 148 | return false; 149 | } 150 | } 151 | -------------------------------------------------------------------------------- /examples/webchannel/chatclient-html/chatclient.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | ChatClient 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 57 | 58 | 59 | 60 |
61 |
62 | 63 | 64 |
Name:
65 |
66 |
67 | Login 68 |
69 |
70 | Username already in use. 71 |
72 | 93 |
94 | 95 | 96 |
97 |
98 | 99 |
100 |
101 |
102 | 103 |
104 |
105 |
106 | 107 |
108 | 119 |
120 | 121 | 122 | 127 | 128 | 129 | 130 | -------------------------------------------------------------------------------- /licenseRule.json: -------------------------------------------------------------------------------- 1 | [ 2 | { 3 | "comment": ["file_pattern_ending: strings matched against the end of a file name.", 4 | "location keys: regular expression matched against the beginning of", 5 | "the file path (relative to the git submodule root).", 6 | "spdx: list of SPDX-License-Expression's allowed in the matching files.", 7 | "-------------------------------------------------------", 8 | "Files with the following endings are Build System licensed,", 9 | "unless they are examples", 10 | "Files with other endings can also be build system files" 11 | ], 12 | "file_pattern_ending": ["CMakeLists.txt", ".cmake", ".pro", ".pri", ".prf", 13 | "configure", "configure.bat", "cmake.in", "plist.in", "CMakeLists.txt.in", 14 | ".cmake.conf", ".tag", "ci_config_linux.json", 15 | ".yaml", "BLACKLIST", ".cfg"], 16 | "location": { 17 | "": { 18 | "comment": "Default", 19 | "file type": "build system", 20 | "spdx": ["BSD-3-Clause"] 21 | }, 22 | "(.*)(examples/|snippets/)": { 23 | "comment": "Example takes precedence", 24 | "file type": "examples and snippets", 25 | "spdx": ["LicenseRef-Qt-Commercial OR BSD-3-Clause"] 26 | } 27 | } 28 | }, 29 | { 30 | "comments": ["Files with the following endings are infrastructure licensed"], 31 | "file_pattern_ending": [".gitattributes", ".gitignore", ".gitmodules", ".gitreview", 32 | "clang-format", "licenseRule.json", "REUSE.toml"], 33 | "location":{ 34 | "": { 35 | "comment": "Default", 36 | "file type": "infrastructure", 37 | "spdx": ["LicenseRef-Qt-Commercial OR BSD-3-Clause"] 38 | } 39 | } 40 | }, 41 | { 42 | "comments": ["Files with the following endings are Tool licensed,", 43 | "unless they are examples.", 44 | "Files with other endings can also be tool files."], 45 | "file_pattern_ending": [".sh", ".py", ".pl", ".bat", ".ps1"], 46 | "location":{ 47 | "": { 48 | "comment": "Default", 49 | "file type": "tools and utils", 50 | "spdx": ["LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0"] 51 | }, 52 | "(.*)(examples/|snippets/)": { 53 | "comment": "Example takes precedence", 54 | "file type": "examples and snippets", 55 | "spdx": ["LicenseRef-Qt-Commercial OR BSD-3-Clause"] 56 | } 57 | } 58 | }, 59 | { 60 | "comment": "Files with the following endings are Documentation licensed.", 61 | "file_pattern_ending": [".qdoc", ".qdocinc" , ".qdocconf", "README", "qt_attribution.json", 62 | "README.md"], 63 | "location":{ 64 | "": { 65 | "comment": "", 66 | "file type": "documentation", 67 | "spdx": ["LicenseRef-Qt-Commercial OR GFDL-1.3-no-invariants-only"] 68 | } 69 | } 70 | }, 71 | { 72 | "comment": ["All other files", 73 | "The licensing is defined only by the file location in the Qt module repository.", 74 | "NO key for this case!", 75 | "This needs to be the last entry of the file."], 76 | "location": { 77 | "": { 78 | "comment": "Default", 79 | "file type": "module and plugin", 80 | "spdx": ["LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only"] 81 | }, 82 | "dist/": { 83 | "comment": "Default", 84 | "file type": "documentation", 85 | "spdx": ["LicenseRef-Qt-Commercial OR GFDL-1.3-no-invariants-only"] 86 | }, 87 | "src/": { 88 | "comment": "Default", 89 | "file type": "module and plugin", 90 | "spdx": ["LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only"] 91 | }, 92 | "tests/": { 93 | "comment": "Default", 94 | "file type": "test", 95 | "spdx": ["LicenseRef-Qt-Commercial OR GPL-3.0-only"] 96 | }, 97 | "(.*)(examples/|snippets/)": { 98 | "comment": "Default", 99 | "file type": "examples and snippets", 100 | "spdx": ["LicenseRef-Qt-Commercial OR BSD-3-Clause"] 101 | }, 102 | "(.*|examples).*/doc/images": { 103 | "comment": "Default", 104 | "file type": "documentation", 105 | "spdx": ["LicenseRef-Qt-Commercial OR GFDL-1.3-no-invariants-only"] 106 | }, 107 | "examples/webchannel/shared/qwebchannel\\.js": { 108 | "comment": "Exception, copyright not only Qt (to be confirmed)", 109 | "file type": "examples and snippets", 110 | "spdx": ["LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only"] 111 | } 112 | } 113 | } 114 | ] 115 | -------------------------------------------------------------------------------- /examples/webchannel/chatclient-qml/qmlchatclient.qml: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2017 The Qt Company Ltd. 2 | // Copyright (C) 2016 basysKom GmbH, author Bernd Lamecker 3 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause 4 | 5 | import QtQuick 6 | import QtQuick.Dialogs 7 | import QtQuick.Controls 8 | import QtQuick.Layouts 9 | import QtWebSockets 10 | import "qrc:/qwebchannel.js" as WebChannel 11 | 12 | ApplicationWindow { 13 | id: root 14 | 15 | property var channel 16 | property string loginName: loginUi.userName.text 17 | property bool loggedIn: false 18 | 19 | title: "Chat client" 20 | width: 640 21 | height: 480 22 | visible: true 23 | 24 | WebSocket { 25 | id: socket 26 | 27 | // the following three properties/functions are required to align the QML WebSocket API 28 | // with the HTML5 WebSocket API. 29 | property var send: function(arg) { 30 | sendTextMessage(arg); 31 | } 32 | 33 | onTextMessageReceived: function(message) { 34 | onmessage({data: message}); 35 | } 36 | 37 | property var onmessage 38 | 39 | active: true 40 | url: "ws://localhost:12345" 41 | 42 | onStatusChanged: { 43 | switch (socket.status) { 44 | case WebSocket.Error: 45 | errorDialog.text = "Error: " + socket.errorString; 46 | errorDialog.visible = true; 47 | break; 48 | case WebSocket.Closed: 49 | errorDialog.text = "Error: Socket at " + url + " closed."; 50 | errorDialog.visible = true; 51 | break; 52 | case WebSocket.Open: 53 | //open the webchannel with the socket as transport 54 | new WebChannel.QWebChannel(socket, function(ch) { 55 | root.channel = ch; 56 | 57 | //connect to the changed signal of the userList property 58 | ch.objects.chatserver.userListChanged.connect(function(args) { 59 | mainUi.userlist.text = ''; 60 | ch.objects.chatserver.userList.forEach(function(user) { 61 | mainUi.userlist.text += user + '\n'; 62 | }); 63 | }); 64 | 65 | //connect to the newMessage signal 66 | ch.objects.chatserver.newMessage.connect(function(time, user, message) { 67 | var line = "[" + time + "] " + user + ": " + message + '\n'; 68 | mainUi.chat.text = mainUi.chat.text + line; 69 | }); 70 | 71 | //connect to the keep alive signal 72 | ch.objects.chatserver.keepAlive.connect(function(args) { 73 | if (loginName !== '' && root.loggedIn) 74 | //and call the keep alive response method as an answer 75 | ch.objects.chatserver.keepAliveResponse(loginName); 76 | }); 77 | }); 78 | 79 | loginWindow.show(); 80 | break; 81 | } 82 | } 83 | } 84 | 85 | MainForm { 86 | id: mainUi 87 | anchors.fill: parent 88 | 89 | Connections { 90 | target: mainUi.message 91 | function onEditingFinished() { 92 | if (mainUi.message.text.length) { 93 | //call the sendMessage method to send the message 94 | root.channel.objects.chatserver.sendMessage(loginName, 95 | mainUi.message.text); 96 | } 97 | mainUi.message.text = ''; 98 | } 99 | } 100 | } 101 | 102 | ApplicationWindow { 103 | id: loginWindow 104 | 105 | title: "Login" 106 | modality: Qt.ApplicationModal 107 | flags: Qt.CustomizeWindowHint | Qt.WindowTitleHint 108 | width: 300 109 | height: 200 110 | 111 | LoginForm { 112 | id: loginUi 113 | anchors.fill: parent 114 | 115 | nameInUseError.visible: false 116 | 117 | Connections { 118 | target: loginUi.loginButton 119 | 120 | function onClicked() { 121 | if (loginName === '') 122 | return; 123 | //call the login method 124 | root.channel.objects.chatserver.login(loginName, function(arg) { 125 | //check the return value for success 126 | if (arg === true) { 127 | loginUi.nameInUseError.visible = false; 128 | loginWindow.close(); 129 | root.loggedIn = true; 130 | } else { 131 | loginUi.nameInUseError.visible = true; 132 | } 133 | }); 134 | } 135 | } 136 | } 137 | } 138 | 139 | Dialog { 140 | id: errorDialog 141 | property alias text: message.text 142 | 143 | anchors.centerIn: parent 144 | standardButtons: Dialog.Close 145 | title: "Chat client" 146 | width: parent.width / 2 147 | 148 | Label { 149 | id: message 150 | } 151 | 152 | onAccepted: { 153 | Qt.quit(); 154 | } 155 | onRejected: { 156 | Qt.quit(); 157 | } 158 | } 159 | } 160 | -------------------------------------------------------------------------------- /tests/auto/qml/data/tst_multiclient.qml: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2016 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com, author Milian Wolff 2 | // Copyright (C) 2016 basysKom GmbH, info@basyskom.com, author Lutz Schönemann 3 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only 4 | 5 | import QtQuick 6 | import QtTest 7 | 8 | import QtWebChannel 9 | import QtWebChannel.Tests 10 | 11 | import "qrc:///qtwebchannel/qwebchannel.js" as JSClient 12 | 13 | TestCase { 14 | name: "MultiClient" 15 | 16 | Client { 17 | id: client1 18 | } 19 | 20 | Client { 21 | id: client2 22 | } 23 | 24 | property int bar: 0 25 | QtObject { 26 | id: foo 27 | 28 | signal ping() 29 | 30 | function pong() 31 | { 32 | return ++bar; 33 | } 34 | 35 | WebChannel.id: "foo" 36 | } 37 | 38 | property var lastMethodArg 39 | QtObject { 40 | id: myObj 41 | property int myProperty: 1 42 | 43 | signal mySignal(var arg) 44 | 45 | function myMethod(arg) 46 | { 47 | lastMethodArg = arg; 48 | } 49 | 50 | WebChannel.id: "myObj" 51 | } 52 | 53 | QtObject { 54 | id: myOtherObj 55 | property var foo: 1 56 | property var bar: 1 57 | WebChannel.id: "myOtherObj" 58 | } 59 | 60 | property var lastFactoryObj 61 | property var createdFactoryObjects: [] 62 | QtObject { 63 | id: myFactory 64 | 65 | function cleanup() { 66 | while (createdFactoryObjects.length) { 67 | var obj = createdFactoryObjects.shift(); 68 | if (obj) { 69 | obj.destroy(); 70 | } 71 | } 72 | } 73 | 74 | function create(id) 75 | { 76 | lastFactoryObj = component.createObject(myFactory, {objectName: id}); 77 | createdFactoryObjects.push(lastFactoryObj); 78 | return lastFactoryObj; 79 | } 80 | WebChannel.id: "myFactory" 81 | } 82 | 83 | Component { 84 | id: component 85 | QtObject { 86 | property var myProperty : 0 87 | function myMethod(arg) { 88 | lastMethodArg = arg; 89 | } 90 | signal mySignal(var arg1, var arg2) 91 | } 92 | } 93 | 94 | TestWebChannel { 95 | id: webChannel 96 | transports: [client1.serverTransport, client2.serverTransport] 97 | registeredObjects: [foo, myObj, myOtherObj, myFactory] 98 | } 99 | 100 | function init() 101 | { 102 | myObj.myProperty = 1 103 | client1.cleanup(); 104 | client2.cleanup(); 105 | } 106 | 107 | function cleanup() { 108 | client1.debug = false; 109 | client2.debug = false; 110 | // delete all created objects 111 | myFactory.cleanup(); 112 | lastFactoryObj = undefined; 113 | createdFactoryObjects = []; 114 | // reschedule current task to end of event loop 115 | wait(1); 116 | } 117 | 118 | function clientInitCallback(channel) 119 | { 120 | channel.objects.foo.ping.connect(function() { 121 | channel.objects.foo.pong(function(value) { 122 | channel.pongAnswer = value; 123 | }); 124 | }); 125 | } 126 | 127 | function test_multiclient() 128 | { 129 | var c1 = client1.createChannel(clientInitCallback); 130 | var c2 = client2.createChannel(clientInitCallback); 131 | 132 | // init, connect & idle messages for two clients 133 | for (var i = 0; i < 3; ++i) { 134 | client1.awaitMessage(); 135 | client2.awaitMessage(); 136 | } 137 | 138 | foo.ping(); 139 | 140 | // invoke of pong method 141 | client1.awaitMessage(); 142 | client2.awaitMessage(); 143 | 144 | compare(c1.pongAnswer, 1); 145 | compare(c2.pongAnswer, 2); 146 | } 147 | 148 | function test_autowrappedObjectsNotInInit() { 149 | var testObj1; 150 | var testObj1Id; 151 | 152 | var channel1 = client1.createChannel(function (channel1) { 153 | channel1.objects.myFactory.create("testObj1", function (obj1) { 154 | testObj1 = lastFactoryObj; 155 | testObj1Id = obj1.__id__; 156 | 157 | // create second channel after factory has created first 158 | // object to make sure that a dynamically created object 159 | // exists but does not get exposed to new channels 160 | createSecondChannel(); 161 | }); 162 | }); 163 | var channel2; 164 | function createSecondChannel() { 165 | // dismiss all messges received before channel creation 166 | client2.cleanup(); 167 | 168 | channel2 = client2.createChannel(function (channel2) { 169 | }); 170 | } 171 | 172 | client1.awaitInit(); 173 | var msg1 = client1.awaitMessage(); 174 | compare(msg1.type, JSClient.QWebChannelMessageTypes.invokeMethod); // create 175 | 176 | client1.awaitIdle(); 177 | 178 | client2.awaitInit(); 179 | client2.awaitIdle(); 180 | 181 | compare(typeof channel2.objects[testObj1Id], "undefined") 182 | } 183 | 184 | function test_autowrappedObjectsNotBroadcasted() { 185 | var testObj2; 186 | var testObj2Id; 187 | 188 | var channel1 = client1.createChannel(function (channel1) { 189 | // create second channel after first channel to make sure 190 | // that a dynamically created object do not get exposed to 191 | // existing channels 192 | createSecondChannel(); 193 | }); 194 | var channel2; 195 | function createSecondChannel() { 196 | // dismiss all messges received before channel creation 197 | client2.cleanup(); 198 | 199 | channel2 = client2.createChannel(function (channel2) { 200 | channel2.objects.myFactory.create("testObj2", function (obj2) { 201 | testObj2 = lastFactoryObj; 202 | testObj2Id = obj2.__id__; 203 | }); 204 | }); 205 | } 206 | 207 | client1.awaitInit(); 208 | client1.awaitIdle(); 209 | 210 | client2.awaitInit(); 211 | var msg2 = client2.awaitMessage(); 212 | compare(msg2.type, JSClient.QWebChannelMessageTypes.invokeMethod); // create 213 | 214 | client2.awaitIdle(); 215 | 216 | compare(typeof channel1.objects[testObj2Id], "undefined") 217 | } 218 | } 219 | -------------------------------------------------------------------------------- /src/webchannel/doc/src/javascript.qdoc: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2014 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com, author Milian Wolff 2 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GFDL-1.3-no-invariants-only 3 | 4 | /*! 5 | \title Qt WebChannel JavaScript API 6 | \page qtwebchannel-javascript.html 7 | 8 | \brief This page explains how to use the JavaScript QWebChannel API in HTML clients. 9 | 10 | \section1 Setting up the JavaScript API 11 | 12 | To communicate with a QWebChannel or \l [QML] WebChannel, a client must use and set up the 13 | JavaScript API provided by \c qwebchannel.js. For clients run inside \l{Qt WebEngine}, you 14 | can load the file via \c qrc:///qtwebchannel/qwebchannel.js. For external clients, you 15 | need to copy the file to your web server. Then instantiate a QWebChannel object and pass 16 | it a transport object and a callback function, which will be invoked once the 17 | initialization of the channel finishes and the published objects become available. An optional 18 | third argument contains an array of converter wrapper functions or a single one. 19 | 20 | The transport object implements a minimal message passing interface. It should be an object 21 | with a \c send() function, which takes a stringified JSON message and transmits it to the 22 | server-side QWebChannelAbstractTransport object. Furthermore, its \c onmessage property should 23 | be called when a message from the server was received. Alternatively, you can use a 24 | \l{Qt WebSockets}{WebSocket} to implement the interface. 25 | 26 | Note that the JavaScript QWebChannel object should be constructed once the transport object is 27 | fully operational. In case of a WebSocket, that means you should create the QWebChannel in the 28 | socket's \c onopen handler. Take a look at the \l{Qt WebChannel Standalone Example} to see how 29 | this is done. 30 | 31 | \note Only a single \c QWebChannel object per transport can be created in the same page. 32 | 33 | A converter wrapper function is either a string with the name of a built-in converter or a 34 | user supplied function that takes the object to process as an argument and returns the 35 | resultant type or undefined if the function does not apply. If undefined is returned the next 36 | converter is processed. If there are no converters that returns a value other than undefined, 37 | processing proceeds as normal. "Date" is the only currently built-in converter function. It 38 | takes a string with an ISO 8601 date and returns a new Date object if the syntax is right and 39 | the date is valid. 40 | 41 | \section1 Interacting with QObjects 42 | 43 | Once the callback passed to the QWebChannel object is invoked, the channel has finished 44 | initialization and all published objects are accessible to the HTML client via the \c channel.objects 45 | property. Thus, assuming an object was published with the identifier "foo", then we can interact with it 46 | as shown in the example below. Note that all communication between the HTML client and 47 | the QML/C++ server is asynchronous. Properties are cached on the HTML side. Furthermore 48 | keep in mind that only QML/C++ data types which can be converted to JSON will be (de-)serialized 49 | properly and thus accessible to HTML clients. 50 | 51 | \code 52 | new QWebChannel(yourTransport, function(channel) { 53 | 54 | // Connect to a signal: 55 | channel.objects.foo.mySignal.connect(function() { 56 | // This callback will be invoked whenever the signal is emitted on the C++/QML side. 57 | console.log(arguments); 58 | }); 59 | 60 | // To make the object known globally, assign it to the window object, i.e.: 61 | window.foo = channel.objects.foo; 62 | 63 | // Invoke a method: 64 | foo.myMethod(arg1, arg2, function(returnValue) { 65 | // This callback will be invoked when myMethod has a return value. Keep in mind that 66 | // the communication is asynchronous, hence the need for this callback. 67 | console.log(returnValue); 68 | }); 69 | 70 | // Read a property value, which is cached on the client side: 71 | console.log(foo.myProperty); 72 | 73 | // Writing a property will instantly update the client side cache. 74 | // The remote end will be notified about the change asynchronously 75 | foo.myProperty = "Hello World!"; 76 | 77 | // To get notified about remote property changes, 78 | // simply connect to the corresponding notify signal: 79 | foo.myPropertyChanged.connect(function() { 80 | console.log(foo.myProperty); 81 | }); 82 | 83 | // One can also access enums that are marked with Q_ENUM: 84 | console.log(foo.MyEnum.MyEnumerator); 85 | }); 86 | \endcode 87 | 88 | \section2 Overloaded methods and signals 89 | 90 | When you publish a \c QObject that has overloaded methods, QWebChannel will resolve 91 | method invocations to the best match. Note that due to JavaScript's type system, there is only 92 | a single 'number' type which maps best to a C++ 'double'. When overloads differ only in the type 93 | of a number-like parameter, QWebChannel will always choose that overload which best matches the 94 | JavaScript 'number' type. 95 | When you connect to an overloaded signal, the QWebChannel client will by default only connect to 96 | the first signal overload of that name. 97 | Additionally, overloads of methods and signals can explicitly be requested by their complete 98 | \c QMetaMethod signature. 99 | Assume we have the following \c QObject subclass on the C++ side: 100 | 101 | \code 102 | class Foo : public QObject 103 | { 104 | Q_OBJECT 105 | slots: 106 | void foo(int i); 107 | void foo(double d); 108 | void foo(const QString &str); 109 | void foo(const QString &str, int i); 110 | 111 | signals: 112 | void bar(int i); 113 | void bar(const QString &str); 114 | void bar(const QString &str, int i); 115 | }; 116 | \endcode 117 | 118 | Then you can interact with this class on the JavaScript side like this: 119 | 120 | \code 121 | // methods 122 | foo.foo(42); // will call the method named foo which best matches the JavaScript number parameter, i.e. foo(double d) 123 | foo.foo("asdf"); // will call foo(const QString &str) 124 | foo.foo("asdf", 42); // will call foo(const QString &str, int i) 125 | foo["foo(int)"](42); // explicitly call foo(int i), *not* foo(double d) 126 | foo["foo(QString)"]("asdf"); // explicitly call foo(const QString &str) 127 | foo["foo(QString,int)"]("asdf", 42); // explicitly call foo(const QString &str, int i) 128 | 129 | // signals 130 | foo.bar.connect(...); // connect to first signal named bar, i.e. bar(int i) 131 | foo["bar(int)"].connect(...); // connect explicitly to bar(int i) 132 | foo["bar(QString)"].connect(...); // connect explicitly to bar(const QString &str) 133 | foo["bar(QString,int)"].connect(...); // connect explicitly to bar(const QString &str, int i) 134 | \endcode 135 | */ 136 | -------------------------------------------------------------------------------- /LICENSES/LGPL-3.0-only.txt: -------------------------------------------------------------------------------- 1 | GNU LESSER GENERAL PUBLIC LICENSE 2 | Version 3, 29 June 2007 3 | 4 | Copyright (C) 2007 Free Software Foundation, Inc. 5 | Everyone is permitted to copy and distribute verbatim copies 6 | of this license document, but changing it is not allowed. 7 | 8 | 9 | This version of the GNU Lesser General Public License incorporates 10 | the terms and conditions of version 3 of the GNU General Public 11 | License, supplemented by the additional permissions listed below. 12 | 13 | 0. Additional Definitions. 14 | 15 | As used herein, "this License" refers to version 3 of the GNU Lesser 16 | General Public License, and the "GNU GPL" refers to version 3 of the GNU 17 | General Public License. 18 | 19 | "The Library" refers to a covered work governed by this License, 20 | other than an Application or a Combined Work as defined below. 21 | 22 | An "Application" is any work that makes use of an interface provided 23 | by the Library, but which is not otherwise based on the Library. 24 | Defining a subclass of a class defined by the Library is deemed a mode 25 | of using an interface provided by the Library. 26 | 27 | A "Combined Work" is a work produced by combining or linking an 28 | Application with the Library. The particular version of the Library 29 | with which the Combined Work was made is also called the "Linked 30 | Version". 31 | 32 | The "Minimal Corresponding Source" for a Combined Work means the 33 | Corresponding Source for the Combined Work, excluding any source code 34 | for portions of the Combined Work that, considered in isolation, are 35 | based on the Application, and not on the Linked Version. 36 | 37 | The "Corresponding Application Code" for a Combined Work means the 38 | object code and/or source code for the Application, including any data 39 | and utility programs needed for reproducing the Combined Work from the 40 | Application, but excluding the System Libraries of the Combined Work. 41 | 42 | 1. Exception to Section 3 of the GNU GPL. 43 | 44 | You may convey a covered work under sections 3 and 4 of this License 45 | without being bound by section 3 of the GNU GPL. 46 | 47 | 2. Conveying Modified Versions. 48 | 49 | If you modify a copy of the Library, and, in your modifications, a 50 | facility refers to a function or data to be supplied by an Application 51 | that uses the facility (other than as an argument passed when the 52 | facility is invoked), then you may convey a copy of the modified 53 | version: 54 | 55 | a) under this License, provided that you make a good faith effort to 56 | ensure that, in the event an Application does not supply the 57 | function or data, the facility still operates, and performs 58 | whatever part of its purpose remains meaningful, or 59 | 60 | b) under the GNU GPL, with none of the additional permissions of 61 | this License applicable to that copy. 62 | 63 | 3. Object Code Incorporating Material from Library Header Files. 64 | 65 | The object code form of an Application may incorporate material from 66 | a header file that is part of the Library. You may convey such object 67 | code under terms of your choice, provided that, if the incorporated 68 | material is not limited to numerical parameters, data structure 69 | layouts and accessors, or small macros, inline functions and templates 70 | (ten or fewer lines in length), you do both of the following: 71 | 72 | a) Give prominent notice with each copy of the object code that the 73 | Library is used in it and that the Library and its use are 74 | covered by this License. 75 | 76 | b) Accompany the object code with a copy of the GNU GPL and this license 77 | document. 78 | 79 | 4. Combined Works. 80 | 81 | You may convey a Combined Work under terms of your choice that, 82 | taken together, effectively do not restrict modification of the 83 | portions of the Library contained in the Combined Work and reverse 84 | engineering for debugging such modifications, if you also do each of 85 | the following: 86 | 87 | a) Give prominent notice with each copy of the Combined Work that 88 | the Library is used in it and that the Library and its use are 89 | covered by this License. 90 | 91 | b) Accompany the Combined Work with a copy of the GNU GPL and this license 92 | document. 93 | 94 | c) For a Combined Work that displays copyright notices during 95 | execution, include the copyright notice for the Library among 96 | these notices, as well as a reference directing the user to the 97 | copies of the GNU GPL and this license document. 98 | 99 | d) Do one of the following: 100 | 101 | 0) Convey the Minimal Corresponding Source under the terms of this 102 | License, and the Corresponding Application Code in a form 103 | suitable for, and under terms that permit, the user to 104 | recombine or relink the Application with a modified version of 105 | the Linked Version to produce a modified Combined Work, in the 106 | manner specified by section 6 of the GNU GPL for conveying 107 | Corresponding Source. 108 | 109 | 1) Use a suitable shared library mechanism for linking with the 110 | Library. A suitable mechanism is one that (a) uses at run time 111 | a copy of the Library already present on the user's computer 112 | system, and (b) will operate properly with a modified version 113 | of the Library that is interface-compatible with the Linked 114 | Version. 115 | 116 | e) Provide Installation Information, but only if you would otherwise 117 | be required to provide such information under section 6 of the 118 | GNU GPL, and only to the extent that such information is 119 | necessary to install and execute a modified version of the 120 | Combined Work produced by recombining or relinking the 121 | Application with a modified version of the Linked Version. (If 122 | you use option 4d0, the Installation Information must accompany 123 | the Minimal Corresponding Source and Corresponding Application 124 | Code. If you use option 4d1, you must provide the Installation 125 | Information in the manner specified by section 6 of the GNU GPL 126 | for conveying Corresponding Source.) 127 | 128 | 5. Combined Libraries. 129 | 130 | You may place library facilities that are a work based on the 131 | Library side by side in a single library together with other library 132 | facilities that are not Applications and are not covered by this 133 | License, and convey such a combined library under terms of your 134 | choice, if you do both of the following: 135 | 136 | a) Accompany the combined library with a copy of the same work based 137 | on the Library, uncombined with any other library facilities, 138 | conveyed under the terms of this License. 139 | 140 | b) Give prominent notice with the combined library that part of it 141 | is a work based on the Library, and explaining where to find the 142 | accompanying uncombined form of the same work. 143 | 144 | 6. Revised Versions of the GNU Lesser General Public License. 145 | 146 | The Free Software Foundation may publish revised and/or new versions 147 | of the GNU Lesser General Public License from time to time. Such new 148 | versions will be similar in spirit to the present version, but may 149 | differ in detail to address new problems or concerns. 150 | 151 | Each version is given a distinguishing version number. If the 152 | Library as you received it specifies that a certain numbered version 153 | of the GNU Lesser General Public License "or any later version" 154 | applies to it, you have the option of following the terms and 155 | conditions either of that published version or of any later version 156 | published by the Free Software Foundation. If the Library as you 157 | received it does not specify a version number of the GNU Lesser 158 | General Public License, you may choose any version of the GNU Lesser 159 | General Public License ever published by the Free Software Foundation. 160 | 161 | If the Library as you received it specifies that a proxy can decide 162 | whether future versions of the GNU Lesser General Public License shall 163 | apply, that proxy's public statement of acceptance of any version is 164 | permanent authorization for you to choose that version for the 165 | Library. 166 | -------------------------------------------------------------------------------- /tests/auto/webchannel/tst_webchannel.h: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2016 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com, author Milian Wolff 2 | // Copyright (C) 2019 Menlo Systems GmbH, author Arno Rehn 3 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only 4 | 5 | #ifndef TST_WEBCHANNEL_H 6 | #define TST_WEBCHANNEL_H 7 | 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | #if QT_CONFIG(future) 16 | #include 17 | #endif 18 | #include 19 | 20 | #include 21 | 22 | struct TestStruct 23 | { 24 | TestStruct(int foo = 0, int bar = 0) 25 | : foo(foo) 26 | , bar(bar) 27 | {} 28 | int foo; 29 | int bar; 30 | 31 | operator QString() const { 32 | return QStringLiteral("TestStruct(foo=%1, bar=%2)").arg(foo).arg(bar); 33 | } 34 | }; 35 | inline bool operator==(const TestStruct &a, const TestStruct &b) 36 | { 37 | return a.foo == b.foo && a.bar == b.bar; 38 | } 39 | inline QDebug operator<<(QDebug &dbg, const TestStruct &ts) 40 | { 41 | QDebugStateSaver dbgState(dbg); 42 | dbg.noquote() << static_cast(ts); 43 | return dbg; 44 | } 45 | Q_DECLARE_METATYPE(TestStruct) 46 | using TestStructVector = std::vector; 47 | Q_DECLARE_METATYPE(TestStructVector) 48 | 49 | QT_BEGIN_NAMESPACE 50 | 51 | class DummyTransport : public QWebChannelAbstractTransport 52 | { 53 | Q_OBJECT 54 | public: 55 | explicit DummyTransport(QObject *parent = nullptr) 56 | : QWebChannelAbstractTransport(parent) 57 | {} 58 | ~DummyTransport() {}; 59 | 60 | void emitMessageReceived(const QJsonObject &message) 61 | { 62 | emit messageReceived(message, this); 63 | } 64 | 65 | QList messagesSent() const { return mMessagesSent; } 66 | 67 | public slots: 68 | void sendMessage(const QJsonObject &message) override 69 | { 70 | mMessagesSent.push_back(message); 71 | } 72 | private: 73 | QList mMessagesSent; 74 | }; 75 | 76 | class TestObject : public QObject 77 | { 78 | Q_OBJECT 79 | 80 | Q_PROPERTY(Foo foo READ foo CONSTANT) 81 | Q_PROPERTY(int asdf READ asdf NOTIFY asdfChanged) 82 | Q_PROPERTY(QString bar READ bar NOTIFY theBarHasChanged) 83 | Q_PROPERTY(QObject * objectProperty READ objectProperty WRITE setObjectProperty NOTIFY objectPropertyChanged) 84 | Q_PROPERTY(TestObject * returnedObject READ returnedObject WRITE setReturnedObject NOTIFY returnedObjectChanged) 85 | Q_PROPERTY(QString prop READ prop WRITE setProp NOTIFY propChanged) 86 | Q_PROPERTY(QString stringProperty READ readStringProperty WRITE setStringProperty BINDABLE bindableStringProperty) 87 | 88 | public: 89 | explicit TestObject(QObject *parent = nullptr) 90 | : QObject(parent) 91 | , mObjectProperty(nullptr) 92 | , mReturnedObject(nullptr) 93 | { } 94 | 95 | enum Foo { 96 | Bar, 97 | Asdf 98 | }; 99 | Q_ENUM(Foo) 100 | 101 | enum TestFlag : quint16 { 102 | FirstFlag = 0x1, 103 | SecondFlag = 0x2 104 | }; 105 | Q_DECLARE_FLAGS(TestFlags, TestFlag) 106 | Q_FLAG(TestFlags) 107 | 108 | Foo foo() const {return Bar;} 109 | int asdf() const {return 42;} 110 | QString bar() const {return QString();} 111 | 112 | QObject *objectProperty() const 113 | { 114 | return mObjectProperty; 115 | } 116 | 117 | TestObject *returnedObject() const 118 | { 119 | return mReturnedObject; 120 | } 121 | 122 | QString prop() const 123 | { 124 | return mProp; 125 | } 126 | 127 | QString readStringProperty() const { return mStringProperty; } 128 | 129 | Q_INVOKABLE void method1() {} 130 | 131 | #if QT_CONFIG(future) 132 | Q_INVOKABLE QFuture futureIntResult() const; 133 | Q_INVOKABLE QFuture futureDelayedIntResult() const; 134 | #ifdef WEBCHANNEL_TESTS_CAN_USE_CONCURRENT 135 | Q_INVOKABLE QFuture futureIntResultFromThread() const; 136 | #endif 137 | Q_INVOKABLE QFuture futureVoidResult() const; 138 | Q_INVOKABLE QFuture futureStringResult() const; 139 | Q_INVOKABLE QFuture cancelledFuture() const; 140 | Q_INVOKABLE QFuture failedFuture() const; 141 | #endif 142 | 143 | protected: 144 | Q_INVOKABLE void method2() {} 145 | 146 | private: 147 | Q_INVOKABLE void method3() {} 148 | 149 | signals: 150 | void sig1(); 151 | void sig2(const QString&); 152 | void asdfChanged(); 153 | void theBarHasChanged(); 154 | void objectPropertyChanged(); 155 | void returnedObjectChanged(); 156 | void propChanged(const QString&); 157 | void replay(); 158 | void overloadSignal(int); 159 | void overloadSignal(float); 160 | 161 | public slots: 162 | void slot1() {} 163 | void slot2(const QString&) {} 164 | 165 | void setReturnedObject(TestObject *obj) 166 | { 167 | mReturnedObject = obj; 168 | emit returnedObjectChanged(); 169 | } 170 | 171 | void setObjectProperty(QObject *object) 172 | { 173 | mObjectProperty = object; 174 | emit objectPropertyChanged(); 175 | } 176 | 177 | void setProp(const QString&prop) {emit propChanged(mProp=prop);} 178 | void fire() {emit replay();} 179 | 180 | double overload(double d) { return d + 1; } 181 | int overload(int i) { return i * 2; } 182 | QObject *overload(QObject *object) { return object; } 183 | QString overload(const QString &str) { return str.toUpper(); } 184 | QString overload(const QString &str, int i) { return str.toUpper() + QString::number(i + 1); } 185 | QString overload(const QJsonArray &v) { return QString::number(v[1].toInt()) + v[0].toString(); } 186 | 187 | void setStringProperty(const QString &v) { mStringProperty = v; } 188 | QBindable bindableStringProperty() { return &mStringProperty; } 189 | QString getStringProperty() const { return mStringProperty; } 190 | void bindStringPropertyToStringProperty2() { bindableStringProperty().setBinding(Qt::makePropertyBinding(mStringProperty2)); } 191 | void setStringProperty2(const QString &string) { mStringProperty2 = string; } 192 | 193 | protected slots: 194 | void slot3() {} 195 | 196 | private slots: 197 | void slot4() {} 198 | 199 | public: 200 | QObject *mObjectProperty; 201 | TestObject *mReturnedObject; 202 | QString mProp; 203 | Q_OBJECT_BINDABLE_PROPERTY(TestObject, QString, mStringProperty); 204 | QProperty mStringProperty2; 205 | }; 206 | 207 | Q_DECLARE_OPERATORS_FOR_FLAGS(TestObject::TestFlags) 208 | 209 | class TestWebChannel : public QObject 210 | { 211 | Q_OBJECT 212 | 213 | Q_PROPERTY(int lastInt READ readInt WRITE setInt NOTIFY lastIntChanged); 214 | Q_PROPERTY(bool lastBool READ readBool WRITE setBool NOTIFY lastBoolChanged); 215 | Q_PROPERTY(double lastDouble READ readDouble WRITE setDouble NOTIFY lastDoubleChanged); 216 | Q_PROPERTY(QVariant lastVariant READ readVariant WRITE setVariant NOTIFY lastVariantChanged); 217 | Q_PROPERTY(QJsonValue lastJsonValue READ readJsonValue WRITE setJsonValue NOTIFY lastJsonValueChanged); 218 | Q_PROPERTY(QJsonObject lastJsonObject READ readJsonObject WRITE setJsonObject NOTIFY lastJsonObjectChanged); 219 | Q_PROPERTY(QJsonArray lastJsonArray READ readJsonArray WRITE setJsonArray NOTIFY lastJsonArrayChanged); 220 | public: 221 | explicit TestWebChannel(QObject *parent = 0); 222 | virtual ~TestWebChannel(); 223 | 224 | public slots: 225 | int readInt() const; 226 | void setInt(int i); 227 | bool readBool() const; 228 | void setBool(bool b); 229 | double readDouble() const; 230 | void setDouble(double d); 231 | QVariant readVariant() const; 232 | void setVariant(const QVariant &v); 233 | QJsonValue readJsonValue() const; 234 | void setJsonValue(const QJsonValue &v); 235 | QJsonObject readJsonObject() const; 236 | void setJsonObject(const QJsonObject &v); 237 | QJsonArray readJsonArray() const; 238 | void setJsonArray(const QJsonArray &v); 239 | 240 | QUrl readUrl() const; 241 | void setUrl(const QUrl &u); 242 | 243 | int readOverload(int i); 244 | QString readOverload(const QString &arg); 245 | QString readOverload(const QString &arg, int i); 246 | 247 | signals: 248 | void lastIntChanged(); 249 | void lastBoolChanged(); 250 | void lastDoubleChanged(); 251 | void lastVariantChanged(); 252 | void lastJsonValueChanged(); 253 | void lastJsonObjectChanged(); 254 | void lastJsonArrayChanged(); 255 | 256 | private slots: 257 | void testRegisterObjects(); 258 | void testDeregisterObjects(); 259 | void testDeregisterObjectAtStart(); 260 | void testInfoForObject(); 261 | void testInvokeMethodConversion(); 262 | void testFunctionOverloading(); 263 | void testSetPropertyConversion(); 264 | void testInvokeMethodOverloadResolution(); 265 | void testDisconnect(); 266 | void testWrapRegisteredObject(); 267 | void testUnwrapObject(); 268 | void testTransportWrapObjectProperties(); 269 | void testRemoveUnusedTransports(); 270 | void testPassWrappedObjectBack(); 271 | void testWrapValues_data(); 272 | void testWrapValues(); 273 | void testWrapObjectWithMultipleTransports(); 274 | void testJsonToVariant_data(); 275 | void testJsonToVariant(); 276 | void testInfiniteRecursion(); 277 | void testAsyncObject(); 278 | void testQProperty(); 279 | void testPropertyUpdateInterval_data(); 280 | void testPropertyUpdateInterval(); 281 | void testPropertyMultipleTransports(); 282 | void testQPropertyBlockUpdates(); 283 | void testBindings(); 284 | void testDeletionDuringMethodInvocation_data(); 285 | void testDeletionDuringMethodInvocation(); 286 | 287 | #if QT_CONFIG(future) 288 | void testAsyncMethodReturningFuture_data(); 289 | void testAsyncMethodReturningFuture(); 290 | #endif 291 | 292 | void qtbug46548_overriddenProperties(); 293 | void qtbug62388_wrapObjectMultipleTransports(); 294 | 295 | private: 296 | DummyTransport *m_dummyTransport; 297 | 298 | int m_lastInt; 299 | bool m_lastBool; 300 | double m_lastDouble; 301 | QVariant m_lastVariant; 302 | QJsonValue m_lastJsonValue; 303 | QJsonObject m_lastJsonObject; 304 | QJsonArray m_lastJsonArray; 305 | QUrl m_lastUrl; 306 | }; 307 | 308 | QT_END_NAMESPACE 309 | 310 | Q_DECLARE_METATYPE(TestObject::Foo) 311 | 312 | #endif // TST_WEBCHANNEL_H 313 | -------------------------------------------------------------------------------- /src/webchannelquick/qqmlwebchannel.cpp: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2016 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com, author 2 | // Milian Wolff 3 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only 4 | // Qt-Security score:significant reason:default 5 | 6 | #undef QT_NO_FOREACH // this file contains unported legacy Q_FOREACH uses 7 | 8 | #include "qqmlwebchannel.h" 9 | #include 10 | #include 11 | #include 12 | #include 13 | 14 | #include "qqmlwebchannelattached_p.h" 15 | 16 | QT_BEGIN_NAMESPACE 17 | 18 | /*! 19 | \qmltype WebChannel 20 | \nativetype QQmlWebChannel 21 | 22 | \inqmlmodule QtWebChannel 23 | \ingroup webchannel-qml 24 | \brief QML interface to QWebChannel. 25 | \since 5.4 26 | 27 | The WebChannel provides a mechanism to transparently access QObject or QML objects from HTML 28 | clients. All properties, signals and public slots can be used from the HTML clients. 29 | 30 | \sa QWebChannel, {Qt WebChannel JavaScript API}{JavaScript API} 31 | */ 32 | 33 | /*! 34 | \qmlproperty list WebChannel::transports 35 | A list of transport objects, which implement QWebChannelAbstractTransport. The transports 36 | are used to talk to the remote clients. 37 | 38 | \sa connectTo(), disconnectFrom() 39 | */ 40 | 41 | /*! 42 | \qmlproperty list WebChannel::registeredObjects 43 | 44 | \brief A list of objects which should be accessible to remote clients. 45 | 46 | The objects must have the attached \l id property set to an identifier, under which the 47 | object is then known on the HTML side. 48 | 49 | Once registered, all signals and property changes are automatically propagated to the clients. 50 | Public invokable methods, including slots, are also accessible to the clients. 51 | 52 | If one needs to register objects which are not available when the component is created, use the 53 | imperative registerObjects method. 54 | 55 | \sa registerObjects(), id 56 | */ 57 | 58 | class QQmlWebChannelPrivate : public QWebChannelPrivate 59 | { 60 | Q_DECLARE_PUBLIC(QQmlWebChannel) 61 | public: 62 | QList registeredObjects; 63 | 64 | void _q_objectIdChanged(const QString &newId); 65 | }; 66 | 67 | /*! 68 | \internal 69 | 70 | Update the name of the sender object, when its attached WebChannel.id property changed. 71 | This is required, since during startup the property is empty and only gets set later on. 72 | */ 73 | void QQmlWebChannelPrivate::_q_objectIdChanged(const QString &newId) 74 | { 75 | Q_Q(QQmlWebChannel); 76 | const QQmlWebChannelAttached *const attached = 77 | qobject_cast(q->sender()); 78 | Q_ASSERT(attached); 79 | Q_ASSERT(attached->parent()); 80 | Q_ASSERT(registeredObjects.contains(attached->parent())); 81 | 82 | QObject *const object = attached->parent(); 83 | const QString &oldId = publisher->registeredObjectIds.value(object); 84 | 85 | if (!oldId.isEmpty()) { 86 | q->deregisterObject(object); 87 | } 88 | 89 | q->registerObject(newId, object); 90 | } 91 | 92 | QQmlWebChannel::QQmlWebChannel(QObject *parent) : QWebChannel(*(new QQmlWebChannelPrivate), parent) 93 | { 94 | } 95 | 96 | QQmlWebChannel::~QQmlWebChannel() { } 97 | 98 | /*! 99 | \qmlmethod void WebChannel::registerObjects(object objects) 100 | Registers the specified \a objects to make them accessible to HTML clients. 101 | \a objects should be a JavaScript Map object. 102 | The key of the map is used as an identifier for the object on the client side. 103 | 104 | Once registered, all signals and property changes are automatically propagated to the clients. 105 | Public invokable methods, including slots, are also accessible to the clients. 106 | 107 | This imperative API can be used to register objects on the fly. For static objects, the 108 | declarative registeredObjects property should be preferred. 109 | 110 | \sa registeredObjects 111 | */ 112 | void QQmlWebChannel::registerObjects(const QVariantMap &objects) 113 | { 114 | Q_D(QQmlWebChannel); 115 | QMap::const_iterator it = objects.constBegin(); 116 | for (; it != objects.constEnd(); ++it) { 117 | QObject *object = it.value().value(); 118 | if (!object) { 119 | qWarning("Invalid QObject given to register under name %s", qPrintable(it.key())); 120 | continue; 121 | } 122 | d->publisher->registerObject(it.key(), object); 123 | } 124 | } 125 | 126 | QQmlWebChannelAttached *QQmlWebChannel::qmlAttachedProperties(QObject *obj) 127 | { 128 | return new QQmlWebChannelAttached(obj); 129 | } 130 | 131 | /*! 132 | \qmlmethod void WebChannel::connectTo(QtObject transport) 133 | 134 | \brief Connects to the \a transport, which represents a communication 135 | channel to a single client. 136 | 137 | The transport object must be an implementation of \l QWebChannelAbstractTransport. 138 | 139 | \sa transports, disconnectFrom() 140 | */ 141 | void QQmlWebChannel::connectTo(QObject *transport) 142 | { 143 | if (QWebChannelAbstractTransport *realTransport = 144 | qobject_cast(transport)) { 145 | QWebChannel::connectTo(realTransport); 146 | } else { 147 | qWarning() << "Cannot connect to transport" << transport 148 | << " - it is not a QWebChannelAbstractTransport."; 149 | } 150 | } 151 | 152 | /*! 153 | \qmlmethod void WebChannel::disconnectFrom(QtObject transport) 154 | 155 | \brief Disconnects the \a transport from this WebChannel. 156 | 157 | The client will not be able to communicate with the WebChannel anymore, nor will it receive any 158 | signals or property updates. 159 | 160 | \sa connectTo() 161 | */ 162 | void QQmlWebChannel::disconnectFrom(QObject *transport) 163 | { 164 | if (QWebChannelAbstractTransport *realTransport = 165 | qobject_cast(transport)) { 166 | QWebChannel::disconnectFrom(realTransport); 167 | } else { 168 | qWarning() << "Cannot disconnect from transport" << transport 169 | << " - it is not a QWebChannelAbstractTransport."; 170 | } 171 | } 172 | 173 | /*! 174 | \property QQmlWebChannel::registeredObjects 175 | 176 | This property holds the list of objects which should be accessible to remote clients. 177 | 178 | The objects must have the attached id property set to an identifier, under which the 179 | object is then known on the HTML side. 180 | 181 | Once registered, all signals and property changes are automatically propagated to the clients. 182 | Public invokable methods, including slots, are also accessible to the clients. 183 | 184 | If one needs to register objects which are not available when the component is created, use the 185 | imperative registerObjects method. 186 | 187 | \sa registerObjects(), id 188 | */ 189 | QQmlListProperty QQmlWebChannel::registeredObjects() 190 | { 191 | return QQmlListProperty(this, nullptr, registeredObjects_append, 192 | registeredObjects_count, registeredObjects_at, 193 | registeredObjects_clear); 194 | } 195 | 196 | void QQmlWebChannel::registeredObjects_append(QQmlListProperty *prop, QObject *object) 197 | { 198 | if (!object) { 199 | qWarning() << "Cannot register null object to WebChannel"; 200 | return; 201 | } 202 | const QQmlWebChannelAttached *const attached = qobject_cast( 203 | qmlAttachedPropertiesObject(object, false /* don't create */)); 204 | if (!attached) { 205 | const QQmlContext *const context = qmlContext(object); 206 | if (context) { 207 | qWarning() << "Cannot register object" << context->nameForObject(object) << '(' << object 208 | << ") without attached WebChannel.id property. Did you forget to set it?"; 209 | } else { 210 | qWarning() << "Cannot register an object without WebChannel attached property."; 211 | } 212 | return; 213 | } 214 | QQmlWebChannel *channel = static_cast(prop->object); 215 | if (!attached->id().isEmpty()) { 216 | // TODO: warning in such cases? 217 | channel->registerObject(attached->id(), object); 218 | } 219 | channel->d_func()->registeredObjects.append(object); 220 | connect(attached, SIGNAL(idChanged(QString)), channel, SLOT(_q_objectIdChanged(QString))); 221 | } 222 | 223 | qsizetype QQmlWebChannel::registeredObjects_count(QQmlListProperty *prop) 224 | { 225 | return static_cast(prop->object)->d_func()->registeredObjects.size(); 226 | } 227 | 228 | QObject *QQmlWebChannel::registeredObjects_at(QQmlListProperty *prop, qsizetype index) 229 | { 230 | return static_cast(prop->object)->d_func()->registeredObjects.at(index); 231 | } 232 | 233 | void QQmlWebChannel::registeredObjects_clear(QQmlListProperty *prop) 234 | { 235 | QQmlWebChannel *channel = static_cast(prop->object); 236 | foreach (QObject *object, channel->d_func()->registeredObjects) { 237 | channel->deregisterObject(object); 238 | } 239 | return channel->d_func()->registeredObjects.clear(); 240 | } 241 | 242 | /*! 243 | \property QQmlWebChannel::transports 244 | 245 | This property holds a list of transport objects, which implement QWebChannelAbstractTransport. 246 | The transports are used to talk to the remote clients. 247 | 248 | \sa connectTo(), disconnectFrom() 249 | */ 250 | QQmlListProperty QQmlWebChannel::transports() 251 | { 252 | return QQmlListProperty(this, nullptr, transports_append, transports_count, 253 | transports_at, transports_clear); 254 | } 255 | 256 | void QQmlWebChannel::transports_append(QQmlListProperty *prop, QObject *transport) 257 | { 258 | QQmlWebChannel *channel = static_cast(prop->object); 259 | channel->connectTo(transport); 260 | } 261 | 262 | qsizetype QQmlWebChannel::transports_count(QQmlListProperty *prop) 263 | { 264 | return static_cast(prop->object)->d_func()->transports.size(); 265 | } 266 | 267 | QObject *QQmlWebChannel::transports_at(QQmlListProperty *prop, qsizetype index) 268 | { 269 | QQmlWebChannel *channel = static_cast(prop->object); 270 | return channel->d_func()->transports.at(index); 271 | } 272 | 273 | void QQmlWebChannel::transports_clear(QQmlListProperty *prop) 274 | { 275 | QWebChannel *channel = static_cast(prop->object); 276 | foreach (QWebChannelAbstractTransport *transport, channel->d_func()->transports) { 277 | channel->disconnectFrom(transport); 278 | } 279 | Q_ASSERT(channel->d_func()->transports.isEmpty()); 280 | } 281 | 282 | QT_END_NAMESPACE 283 | 284 | #include "moc_qqmlwebchannel.cpp" 285 | --------------------------------------------------------------------------------