-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
60 lines (56 loc) · 2.03 KB
/
main.cpp
File metadata and controls
60 lines (56 loc) · 2.03 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
#include "gfile.h"
#include <QGuiApplication>
#include <QApplication>
#include <QQmlApplicationEngine>
#include <gfile.h>
#include <QMessageBox>
#include <QSharedMemory>
#include "delbuttontype.h"
#include "logger.h"
int main(int argc, char *argv[])
{
QGuiApplication app(argc, argv);
QSharedMemory sharedMemory("545Rand");
QApplication* app2=new QApplication(argc, argv);
if (sharedMemory.attach()) {
// 已附加到现有内存段,说明已有实例运行
QMessageBox::warning(nullptr, "545Rand", "程序已经在运行中");
return 3;
}
else{
// 创建共享内存段
if (!sharedMemory.create(1)) {
QMessageBox::critical(nullptr, "错误", "无法创建共享内存段");
return 1;
}
qmlRegisterUncreatableMetaObject(DelButtonType::staticMetaObject, "DelegateUI.Controls", 1, 0
, "DelButtonType", "Access to enums & flags only");
qmlRegisterType<GFile>("GFile",1,2,"GFile");
qmlRegisterSingletonType<Logger>(
"Logger", 1, 0, "Logger",
[](QQmlEngine *engine, QJSEngine *scriptEngine) -> QObject * {
Q_UNUSED(engine)
Q_UNUSED(scriptEngine)
return new Logger();
}
);
QQmlApplicationEngine engine;
GFile file;
file.setSource("./scale.txt");
QString s=file.read();
qputenv("QT_SCALE_FACTOR",s.toLatin1());
file.setSource("./run.ini");
s=file.read();
QUrl url(QStringLiteral("qrc:/main.qml"));
if(s=="bar"){
url=QStringLiteral("qrc:/main_bar.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);
return app.exec();
}
}