#include "mainwindow.h" #include "SingleInstanceManager.h" #include #include #include #include #ifdef _WIN32 #include #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("WorkpieceSpliceApp_SingleInstance_Key"); if (instanceManager.isAnotherInstanceRunning()) { // 已有实例在运行,显示提示信息并退出 QMessageBox::information(nullptr, QObject::tr("应用程序已运行"), QObject::tr("工件拼接应用程序已经在运行中,请勿重复启动!"), QMessageBox::Ok); return 0; } // 没有其他实例运行,正常启动应用程序 MainWindow w; w.show(); return a.exec(); }