diff options
author | Ulf Hermann <ulf.hermann@theqtcompany.com> | 2016-03-09 16:38:29 +0100 |
---|---|---|
committer | Ulf Hermann <ulf.hermann@theqtcompany.com> | 2016-03-30 11:56:40 +0000 |
commit | a14b1e4c4787fa1e4a7d470444c248fd08817105 (patch) | |
tree | 53cd8d65c7aa8a983e1381a072a511c81ee028c5 /examples/scxml/mediaplayer-qml-static | |
parent | 703c6a6bee98c5d316de408867982b1684ad550b (diff) |
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 <erik.verbruggen@theqtcompany.com>
Diffstat (limited to 'examples/scxml/mediaplayer-qml-static')
-rw-r--r-- | examples/scxml/mediaplayer-qml-static/mediaplayer-qml-static.cpp | 5 | ||||
-rw-r--r-- | examples/scxml/mediaplayer-qml-static/mediaplayer-qml-static.qml | 6 |
2 files changed, 6 insertions, 5 deletions
diff --git a/examples/scxml/mediaplayer-qml-static/mediaplayer-qml-static.cpp b/examples/scxml/mediaplayer-qml-static/mediaplayer-qml-static.cpp index 9aa1ea3..6dd263e 100644 --- a/examples/scxml/mediaplayer-qml-static/mediaplayer-qml-static.cpp +++ b/examples/scxml/mediaplayer-qml-static/mediaplayer-qml-static.cpp @@ -58,12 +58,9 @@ int main(int argc, char *argv[]) { QGuiApplication app(argc, argv); - MediaPlayerStateMachine stateMachine; - stateMachine.init(); - stateMachine.start(); + qmlRegisterType<MediaPlayerStateMachine>("MediaPlayerStateMachine", 1, 0, "MediaPlayerStateMachine"); QQmlApplicationEngine engine; - engine.rootContext()->setContextProperty(QStringLiteral("mediaPlayerStateMachine"), &stateMachine); engine.load(QUrl(QStringLiteral("qrc:///mediaplayer-qml-static.qml"))); if (engine.rootObjects().isEmpty()) return -1; diff --git a/examples/scxml/mediaplayer-qml-static/mediaplayer-qml-static.qml b/examples/scxml/mediaplayer-qml-static/mediaplayer-qml-static.qml index 252d69b..170b938 100644 --- a/examples/scxml/mediaplayer-qml-static/mediaplayer-qml-static.qml +++ b/examples/scxml/mediaplayer-qml-static/mediaplayer-qml-static.qml @@ -48,6 +48,10 @@ ** ****************************************************************************/ +import MediaPlayerStateMachine 1.0 + Mediaplayer { - stateMachine: mediaPlayerStateMachine + stateMachine: MediaPlayerStateMachine { + running: true + } } |