48 lines
1.2 KiB
C++
Raw Normal View History

2025-12-10 00:01:32 +08:00
#include "mainwindow.h"
2025-12-27 09:34:02 +08:00
#include "SingleInstanceManager.h"
2025-12-10 00:01:32 +08:00
#include <QApplication>
2025-12-27 09:34:02 +08:00
#include <QIcon>
#include <QMessageBox>
#include <QObject>
#ifdef _WIN32
#include <windows.h>
#endif
2025-12-10 00:01:32 +08:00
int main(int argc, char *argv[])
{
2025-12-27 09:34:02 +08:00
#ifdef _WIN32
// 设置控制台代码页为 UTF-8解决中文乱码
SetConsoleOutputCP(CP_UTF8);
SetConsoleCP(CP_UTF8);
#endif
2025-12-10 00:01:32 +08:00
QApplication a(argc, argv);
2025-12-27 09:34:02 +08:00
// 设置应用程序图标
#ifdef _WIN32
a.setWindowIcon(QIcon(":/common/resource/logo.ico"));
#else
a.setWindowIcon(QIcon(":/common/resource/logo.png"));
#endif
// 使用 SingleInstanceManager 检查单例
SingleInstanceManager instanceManager("WorkpiecePositionApp_SingleInstance_Key");
if (instanceManager.isAnotherInstanceRunning()) {
// 已有实例在运行,显示提示信息并退出
QMessageBox::information(nullptr,
QObject::tr("应用程序已运行"),
QObject::tr("工件定位应用程序已经在运行中,请勿重复启动!"),
QMessageBox::Ok);
return 0;
}
// 没有其他实例运行,正常启动应用程序
2025-12-10 00:01:32 +08:00
MainWindow w;
w.show();
2025-12-27 09:34:02 +08:00
2025-12-10 00:01:32 +08:00
return a.exec();
}