From a14b1e4c4787fa1e4a7d470444c248fd08817105 Mon Sep 17 00:00:00 2001 From: Ulf Hermann Date: Wed, 9 Mar 2016 16:38:29 +0100 Subject: Change examples to follow best practices Adding QObjects as context properties to QML engines is not the best way to interoperate between QML and C++. This change exposes all state machines as proper QML components and instantiates them from QML. Also, it drops all the now unnecessary init() calls. Change-Id: Id44b4038542dd9469e02831c1bb54f096af1b6ff Reviewed-by: Erik Verbruggen --- examples/scxml/invoke-static/invoke-static.cpp | 5 +---- examples/scxml/invoke-static/invoke-static.qml | 6 +++++- 2 files changed, 6 insertions(+), 5 deletions(-) (limited to 'examples/scxml/invoke-static') diff --git a/examples/scxml/invoke-static/invoke-static.cpp b/examples/scxml/invoke-static/invoke-static.cpp index c955ebe..d53eb48 100644 --- a/examples/scxml/invoke-static/invoke-static.cpp +++ b/examples/scxml/invoke-static/invoke-static.cpp @@ -58,15 +58,12 @@ int main(int argc, char *argv[]) { QGuiApplication app(argc, argv); - Directions stateMachine; + qmlRegisterType("Directions", 1, 0, "Directions"); QQmlApplicationEngine engine; - engine.rootContext()->setContextProperty(QStringLiteral("directions"), &stateMachine); engine.load(QUrl(QStringLiteral("qrc:/invoke-static.qml"))); if (engine.rootObjects().isEmpty()) return -1; - stateMachine.start(); - return app.exec(); } diff --git a/examples/scxml/invoke-static/invoke-static.qml b/examples/scxml/invoke-static/invoke-static.qml index 68f0556..dc59e1b 100644 --- a/examples/scxml/invoke-static/invoke-static.qml +++ b/examples/scxml/invoke-static/invoke-static.qml @@ -48,6 +48,10 @@ ** ****************************************************************************/ +import Directions 1.0 + MainView { - stateMachine: directions + stateMachine: Directions { + running: true + } } -- cgit v1.2.3