#include "mainwindow.h" #include "SingleInstanceManager.h" #include #include #include #include int main(int argc, char *argv[]) { QApplication a(argc, argv); // 设置应用程序图标 a.setWindowIcon(QIcon(":/resource/logo.png")); // 使用 SingleInstanceManager 检查单例 SingleInstanceManager instanceManager("WorkpieceApp_SingleInstance_Key"); if (instanceManager.isAnotherInstanceRunning()) { // 已有实例在运行,显示提示信息并退出 QMessageBox::information(nullptr, QObject::tr("应用程序已运行"), QObject::tr("工件定位应用程序已经在运行中,请勿重复启动!"), QMessageBox::Ok); return 0; } // 没有其他实例运行,正常启动应用程序 MainWindow w; w.show(); return a.exec(); }