-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathmain.cpp
More file actions
51 lines (37 loc) · 1.52 KB
/
main.cpp
File metadata and controls
51 lines (37 loc) · 1.52 KB
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
#include <QGuiApplication>
#include <QQmlApplicationEngine>
#include <QSurfaceFormat>
#include <QQmlContext>
#include <QCommandLineParser>
#include "appcore.h"
int main(int argc, char *argv[])
{
QGuiApplication app(argc, argv);
QSurfaceFormat format;
format.setSamples(8);
QSurfaceFormat::setDefaultFormat(format);
QCommandLineParser parser;
parser.setApplicationDescription("SVG to QML converter.");
parser.addHelpOption();
parser.addVersionOption();
parser.addPositionalArgument("source", QCoreApplication::translate("main", "Source svg file."));
parser.addPositionalArgument("destination", QCoreApplication::translate("main", "Destination qml file."));
parser.process(app);
const QStringList args = parser.positionalArguments();
QString source = (args.count()>0)? args[0] : "";
QString dest = (args.count()>1)? args[1] : "file:./tmp.qml";
AppCore * appCore = new AppCore(nullptr);
QQmlApplicationEngine engine;
engine.rootContext()->setContextProperty("appCore", QVariant::fromValue(appCore));
const QUrl url(QStringLiteral("qrc:/main.qml"));
QObject::connect(&engine, &QQmlApplicationEngine::objectCreated, &app, [url](QObject *obj, const QUrl &objUrl) {
if (!obj && url == objUrl) { QCoreApplication::exit(-1); }
}, Qt::QueuedConnection);
engine.rootContext()->setContextProperty("appCore", appCore);
engine.load(url);
//-- Create
if ( !source.isEmpty() ) {
appCore->svg2qml(source, dest);
}
return app.exec();
}