-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.cpp
73 lines (60 loc) · 1.94 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
#include <QApplication>
#include <QQmlApplicationEngine>
#include <QQmlContext>
#include <QQuickStyle>
#include <QIcon>
#include <iostream>
#include "CRunnable.h"
#include "CMainWindow.h"
int main(int argc, char *argv[])
{
// Disable multiple activation
CRunnable Runnable("GrepToolQML-X8WAT-ME6UR-FHCBW-KF739-LWWkV");
if (!Runnable.tryToRun())
{
std::cerr << "GrepToolQML is already running." << std::endl;
return -1;
}
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
QApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
#endif
QApplication app(argc, argv);
QApplication::setOrganizationName("Presire");
// Disable multiple activation
// Trying to close the Lock File, if the attempt is unsuccessful for 100 milliseconds,
// then there is a Lock File already created by another process.
// Therefore, we throw a warning and close the program
//QLockFile lockFile(QDir::temp().absoluteFilePath("GrepToolQML.lock"));
//if(!lockFile.tryLock(100))
//{
// return 1;
//}
// Set GrepToolQML's Icon
app.setWindowIcon(QIcon(":/Image/GrepToolQML.png"));
QSettings settings;
CMainWindow mainWindow;
bool bColorMode = mainWindow.getColorMode();
if (bColorMode)
{
QQuickStyle::setStyle("Material");
}
else
{
QQuickStyle::setStyle("Universal");
}
// Register the class so that it can be used in QML
qmlRegisterType<CMainWindow>("MainWindow", 1, 0, "CMainWindow");
QQmlApplicationEngine engine;
#ifdef PINEPHONE
const QUrl url(QStringLiteral("qrc:/mainPinePhone.qml"));
#else
const QUrl url(QStringLiteral("qrc:/main.qml"));
#endif
QObject::connect(&engine, &QQmlApplicationEngine::objectCreated,
&app, [url](QObject *obj, const QUrl &objUrl) {
if (!obj && url == objUrl)
QCoreApplication::exit(-1);
}, Qt::QueuedConnection);
engine.load(url);
return app.exec();
}