forked from game1024/OpenSpeedy
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
66 lines (59 loc) · 1.87 KB
/
Copy pathmain.cpp
File metadata and controls
66 lines (59 loc) · 1.87 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
63
64
65
66
#include "mainwindow.h"
#include "windbg.h"
#include <QApplication>
#include <QLocalServer>
#include <QLocalSocket>
#include <QLocale>
#include <QTranslator>
int
main(int argc, char* argv[])
{
SetUnhandledExceptionFilter(createMiniDump);
QApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
QApplication::setAttribute(Qt::AA_UseHighDpiPixmaps);
QApplication a(argc, argv);
// 检查是否已有实例在运行
QString unique = "OpenSpeedy";
QLocalSocket socket;
socket.connectToServer(unique);
if (socket.waitForConnected(500))
{
socket.close();
return -1;
}
// 使用资源文件中的图标
QIcon appIcon;
appIcon.addFile(":/icons/images/icon_16.ico", QSize(16, 16));
appIcon.addFile(":/icons/images/icon_32.ico", QSize(32, 32));
appIcon.addFile(":/icons/images/icon_64.ico", QSize(64, 64));
a.setWindowIcon(appIcon);
QSettings settings =
QSettings(QCoreApplication::applicationDirPath() + "/config.ini",
QSettings::IniFormat);
QTranslator translator;
const QString baseName =
"OpenSpeedy_" +
settings.value(CONFIG_LANGUAGE, QLocale().system().name()).toString();
if (translator.load(":/i18n/translations/" + baseName))
{
a.installTranslator(&translator);
}
MainWindow w;
w.resize(800, 768);
w.show();
// 创建并启动本地服务器
QLocalServer server;
QLocalServer::removeServer(unique);
server.listen(unique);
// 当用户尝试再运行一个进程时,将窗口显示到最前台
QObject::connect(&server,
&QLocalServer::newConnection,
[&]
{
w.show();
w.raise();
w.showNormal();
w.activateWindow();
});
return a.exec();
}