blob: 762212b287ad77753a7bb4dc5692a8bafb1a9fa5 (
plain)
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
70
71
72
|
#include <QApplication>
#include <QUrl>
#include <QFileInfo>
#include <QDir>
#include <QmlContext>
#include <QmlComponent>
#include <qfxview.h>
#include <QDebug>
QFxView *canvas = 0;
class QmlLauncher : public QObject
{
Q_OBJECT
public:
QmlLauncher() {}
Q_INVOKABLE void launch(const QString &fileName)
{
QUrl url(fileName);
QFileInfo fi(fileName);
if (fi.exists()) {
url = QUrl::fromLocalFile(fi.absoluteFilePath());
QmlContext *ctxt = canvas->rootContext();
QDir dir(fi.path()+"/dummydata", "*.qml");
QStringList list = dir.entryList();
for (int i = 0; i < list.size(); ++i) {
QString qml = list.at(i);
QFile f(dir.filePath(qml));
f.open(QIODevice::ReadOnly);
QByteArray data = f.readAll();
QmlComponent comp(canvas->engine());
comp.setData(data, QUrl());
QObject *dummyData = comp.create();
if(comp.isError()) {
QList<QmlError> errors = comp.errors();
foreach (const QmlError &error, errors) {
qWarning() << error;
}
}
if (dummyData) {
qml.truncate(qml.length()-4);
ctxt->setContextProperty(qml, dummyData);
dummyData->setParent(this);
}
}
}
canvas->setUrl(fileName);
canvas->execute();
}
};
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
QmlLauncher *launcher = new QmlLauncher;
canvas = new QFxView;
QmlContext *ctxt = canvas->rootContext();
ctxt->setContextProperty("qmlLauncher", launcher);
canvas->setUrl(QUrl("qrc:/loader.qml"));
canvas->execute();
canvas->show();
return app.exec();
}
#include "main.moc"
|