2025-12-27 09:34:02 +08:00

48 lines
1.2 KiB
C++
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#include "mainwindow.h"
#include "SingleInstanceManager.h"
#include <QApplication>
#include <QIcon>
#include <QMessageBox>
#include <QObject>
#ifdef _WIN32
#include <windows.h>
#endif
int main(int argc, char *argv[])
{
#ifdef _WIN32
// 设置控制台代码页为 UTF-8解决中文乱码
SetConsoleOutputCP(CP_UTF8);
SetConsoleCP(CP_UTF8);
#endif
QApplication a(argc, argv);
// 设置应用程序图标
#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;
}
// 没有其他实例运行,正常启动应用程序
MainWindow w;
w.show();
return a.exec();
}