-
Notifications
You must be signed in to change notification settings - Fork 52
Expand file tree
/
Copy pathmain.cpp
More file actions
62 lines (59 loc) · 1.83 KB
/
main.cpp
File metadata and controls
62 lines (59 loc) · 1.83 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 "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);
QTranslator translator;
const QStringList uiLanguages = QLocale::system().uiLanguages();
for (const QString& locale : uiLanguages)
{
const QString baseName = "OpenSpeedy_" + QLocale(locale).name();
if (translator.load(":/i18n/" + baseName))
{
a.installTranslator(&translator);
break;
}
}
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();
}