Custom Runtime Example

Demonstrates how to create a Custom QmlLive Runtime.

Screenshot of the Custom QmlLive Runtime

Creating a custom runtime with QmlLive features allows you to use your QML view setup, combined with additional C++ code and the QmlLive system.

Start with the LiveNodeEngine class. We need to modify this class to be able to receive workspace changes and active document updates. By default, the IPC listens to port 10234.

The code snippet below shows a minimal custom QmlLive runtime:

#include <QtGui>
#include <QtQuick>

// Use QmlLive headers
#include "livenodeengine.h"
#include "remotereceiver.h"

class MyQmlApplicationEngine : public QQmlApplicationEngine

    MyQmlApplicationEngine(const QString &mainQml); // Perform some setup here

    QString mainQml() const;
    QQuickWindow *mainWindow();
    QList<QQmlError> warnings() const;

    // ...

int main(int argc, char **argv)
    QGuiApplication app(argc, argv);
    MyQmlApplicationEngine engine(QStringLiteral("qml/customruntime-window.qml"));

    if (!qEnvironmentVariableIsSet("MY_APP_ENABLE_QMLLIVE"))
        return app.exec();

#if defined(QT_NO_DEBUG)
    qWarning() << "QmlLive support was disabled at compile time";
    LiveNodeEngine node;

    // Let QmlLive know your runtime

    // Allow it to display QML components with non-QQuickWindow root object
    QQuickView fallbackView(&engine, 0);

    // Tell it where file updates should be stored relative to
                      LiveNodeEngine::AllowUpdates | LiveNodeEngine::UpdatesAsOverlay);

    // Listen to IPC call from remote QmlLive Bench
    RemoteReceiver receiver;

    // Advanced use: let it know the initially loaded QML component (do this
    // only after registering to receiver!)
    node.usePreloadedDocument(engine.mainQml(), engine.mainWindow(), engine.warnings());

    return app.exec();

To specify project depedencies on platforms that support pkg-config, add the following line to your project file. This is assuming QmlLive is installed on your build host:

CONFIG += link_pkgconfig
PKGCONFIG += qmllive

In case if your system doesn't support pkg-config, to compile everything directly into your application, include file $(QMLLIVEPROJECT)/src/src.pri by adding the line into your project file:




© 2019 Luxoft Sweden AB. Documentation contributions included herein are the copyrights of their respective owners. The documentation provided herein is licensed under the terms of the GNU Free Documentation License version 1.3 as published by the Free Software Foundation. Qt and respective logos are trademarks of The Qt Company Ltd. in Finland and/or other countries worldwide. All other trademarks are property of their respective owners.