-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.cpp
69 lines (58 loc) · 2.49 KB
/
main.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
#include <QGuiApplication>
#include <QQmlApplicationEngine>
#ifdef QT_QMLLIVE
#include "livenodeengine.h"
#include "remotereceiver.h"
#endif
int main(int argc, char *argv[])
{
QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
QGuiApplication app(argc, argv);
QQmlApplicationEngine engine;
engine.load(QUrl(QStringLiteral("qrc:/main.qml")));
if (engine.rootObjects().isEmpty())
return -1;
#ifdef QT_QMLLIVE
qDebug() << "app.applicationDirPath(): " << app.applicationDirPath();
qDebug() << "writable data location: " << QStandardPaths::writableLocation(QStandardPaths::DataLocation);
auto writeLocation = QStandardPaths::writableLocation(QStandardPaths::DataLocation);
auto qmlFile = "main.qml";
LiveNodeEngine node;
// Let QmlLive know your runtime
node.setQmlEngine(&engine);
// Allow it to display QML components with non-QQuickWindow root object
QQuickView fallbackView(&engine, 0);
node.setFallbackView(&fallbackView);
// Tell it where file updates should be stored relative to
#ifdef Q_OS_ANDROID
// QStandardPaths::writableLocation(QStandardPaths::DataLocation);
QString workspaceRoot = writeLocation;
qDebug() << "workspaceRoot: " << workspaceRoot;
#else
// QString workspaceRoot = SRCDIR;
QString workspaceRoot = writeLocation;
qDebug() << "workspaceRoot: " << workspaceRoot;
#endif //
node.setWorkspace(workspaceRoot,
LiveNodeEngine::AllowUpdates
/*| LiveNodeEngine::UpdatesAsOverlay*/ // uncommenting it breaks workspace
);
// Listen to IPC call from remote QmlLive Bench
RemoteReceiver receiver;
QObject::connect(&receiver, &RemoteReceiver::activateDocument, [&](const LiveDocument& document) {
qDebug() << "** document activated: " << document.relativeFilePath();
});
QObject::connect(&receiver, &RemoteReceiver::updateDocument, [&](const LiveDocument &document, const QByteArray &content) {
qDebug() << "** document updated: " << document.relativeFilePath();
});
receiver.registerNode(&node);
receiver.listen(10234);
QQuickWindow* window = qobject_cast<QQuickWindow *>(engine.rootObjects().first());
// Advanced use: let it know the initially loaded QML component (do this
// only after registering to receiver!)
QList<QQmlError> warnings;
node.usePreloadedDocument(qmlFile, window, warnings);
qDebug() << "QMLLIVE mode: listening " << 10234;
#endif
return app.exec();
}