-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
62 lines (51 loc) · 1.65 KB
/
Copy pathmain.cpp
File metadata and controls
62 lines (51 loc) · 1.65 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
52
53
54
55
56
57
58
59
60
61
62
#include <QApplication>
#include <QGuiApplication>
#include <QQmlApplicationEngine>
#include <QQmlContext>
#include <QSettings>
#include <QThread>
#include <QObject>
#include <QIcon>
#include "QMLAdapter.h"
#include "TableModel.h"
#include "Adapters.h"
int main(int argc, char *argv[])
{
QCoreApplication::addLibraryPath("./");
QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
// QGuiApplication app(argc, argv);
//swap with QApplication, because QtCharts require it
QApplication app(argc, argv);
app.setWindowIcon(QIcon("data/logo.png"));
QQmlApplicationEngine engine;
//! [registertype]
qmlRegisterType<TableModel>("TableModel", 1, 0, "TableModel");
//
QSettings settings("gui.config", QSettings::NativeFormat);
//
QMLAdapter qmlAdapter(&settings);
engine.rootContext()->setContextProperty("qmlAdapter", &qmlAdapter);
//
DataModel dataModel;
//
TableModel tableModel;
tableModel.setDataModel(&dataModel);
engine.rootContext()->setContextProperty("tableModel", &tableModel);
FakeAdapter adapter(&dataModel, &qmlAdapter);
engine.rootContext()->setContextProperty("adapter", &adapter);
QThread thread;
adapter.moveToThread(&thread);
thread.start();
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.load(url);
auto ret = app.exec();
thread.quit();
thread.wait();
return ret;
}