diff options
author | Juha Vuolle <juha.vuolle@qt.io> | 2023-03-10 15:19:09 +0200 |
---|---|---|
committer | Juha Vuolle <juha.vuolle@qt.io> | 2023-03-17 13:02:12 +0200 |
commit | 3314da2f16d2b0c1f52e8da07c299ee983314c59 (patch) | |
tree | 07d96f1197968222b79af4445194e60407c17f62 /examples/scxml/trafficlight-qml-dynamic/trafficlight-qml-dynamic.cpp | |
parent | 3cb2fa15fc9b73453ada4b36577322bbea86c52c (diff) |
Revamp scxml trafficlight examples
In addition to general modernization, this commit changes
the trafficlight structure slightly so that the qml-static
and qml-dynamic variants have their own copies of the QML
files.
This way the examples remain standalone examples
whilst using the contemporary qt_add_qml_module, without
needing to introduce a shared common QML module. A shared
common QML module is a viable option but would unnecesarily
complicate example build/link/deployments.
Pick-to: 6.5
Task-number: QTBUG-111323
Change-Id: I7a289db2d2927d97438556362e4b2eff53821020
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
Diffstat (limited to 'examples/scxml/trafficlight-qml-dynamic/trafficlight-qml-dynamic.cpp')
-rw-r--r-- | examples/scxml/trafficlight-qml-dynamic/trafficlight-qml-dynamic.cpp | 23 |
1 files changed, 6 insertions, 17 deletions
diff --git a/examples/scxml/trafficlight-qml-dynamic/trafficlight-qml-dynamic.cpp b/examples/scxml/trafficlight-qml-dynamic/trafficlight-qml-dynamic.cpp index 49d7549..5b945b7 100644 --- a/examples/scxml/trafficlight-qml-dynamic/trafficlight-qml-dynamic.cpp +++ b/examples/scxml/trafficlight-qml-dynamic/trafficlight-qml-dynamic.cpp @@ -1,28 +1,17 @@ -// Copyright (C) 2016 The Qt Company Ltd. +// Copyright (C) 2023 The Qt Company Ltd. // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause -#include <QGuiApplication> -#include <QQmlApplicationEngine> -#include <QQmlContext> -#include <QScxmlStateMachine> +#include <QtGui/qguiapplication.h> +#include <QtQml/qqmlapplicationengine.h> int main(int argc, char *argv[]) { QGuiApplication app(argc, argv); - /* Register QScxmlStateMachine as TrafficLightStateMachine. This is required to have a type - * for the state machine and allows full code completion in the static case, since we - * share the QML code. */ - qmlRegisterUncreatableType<QScxmlStateMachine>("TrafficLightStateMachine", - 1, 0, - "TrafficLightStateMachine", - QLatin1String("TrafficLightStateMachine is not creatable.")); - QQmlApplicationEngine engine; - engine.load(QUrl(QStringLiteral("qrc:///trafficlight-qml-dynamic.qml"))); - if (engine.rootObjects().isEmpty()) - return -1; + QObject::connect(&engine, &QQmlApplicationEngine::objectCreationFailed, &app, + [](){ QCoreApplication::exit(EXIT_FAILURE); }, Qt::QueuedConnection); + engine.loadFromModule("TrafficLightApplication", "MainView"); return app.exec(); } - |