-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.cpp
76 lines (69 loc) · 2.04 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
70
71
72
73
74
75
76
#include <QQmlApplicationEngine>
#include <QQmlContext>
#include <QApplication>
#include <QStandardPaths>
#include <QDir>
#include <QIcon>
#include "mytreemodel.h"
#include "global.h"
#include "com/runmain.h"
#include "dao/treedao.h"
#include "com/sqlite_manager.h"
#include "com/log.h"
#include "cfg.h"
//#include "test.h"
#include "libxdb.h"
void initDB();
void initPath();
void exit_();
int main(int argc, char *argv[]) {
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
QApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
#endif
QApplication app(argc, argv);
#ifdef Q_OS_MAC
app.setWindowIcon(QIcon(":/assets/logo.icns"));
#endif
qmlRegisterType<MyTreeModel>("XDB.Tree", 1, 0, "TreeModel");
qmlRegisterType<MyTreeNode>("XDB.Tree", 1, 0, "TreeElement");
// test2();
global::DB_Async->start();
Log::INS().init("");
initPath();
initDB();
RunMain::INS().init();
global::engine = new QQmlApplicationEngine();
const QUrl url(QStringLiteral("qrc:/qml/main.qml"));
QObject::connect(global::engine, &QQmlApplicationEngine::objectCreated, &app, [url](QObject *obj, const QUrl &objUrl) {
if (!obj && url == objUrl) {
QCoreApplication::exit(-1);
}
}, Qt::QueuedConnection);
global::engine->rootContext()->setContextProperty("$app", global::app);
global::engine->rootContext()->setContextProperty("$l", global::l);
global::engine->load(url);
QObject::connect(global::engine, &QQmlEngine::quit, qApp, &QCoreApplication::quit);
QObject::connect(qApp, &QGuiApplication::aboutToQuit, qApp, &exit_);
return app.exec();
}
void initPath() {
QDir dir;
if(!dir.exists(global::getDataDir())) {
dir.mkpath(global::getDataDir());
}
}
void initDB() {
global::DB_Async->exe([=] {
if (global::sqlm->openDB()) {
global::sqlm->init();
TreeDao::INS().init();
}
});
}
void exit_() {
XdbClose();
global::DB_Async->close();
global::sqlm->close();
global::clear();
qDebug() << "-------------- exit_ --------------";
}