45 lines
1.2 KiB
C++
45 lines
1.2 KiB
C++
|
|
#include "mainwindow.h"
|
|||
|
|
#include "SingleInstanceManager.h"
|
|||
|
|
#include "AuthView.h"
|
|||
|
|
#include "Version.h"
|
|||
|
|
|
|||
|
|
#include <QApplication>
|
|||
|
|
#include <QIcon>
|
|||
|
|
#include <QMessageBox>
|
|||
|
|
#include <QObject>
|
|||
|
|
#include <string>
|
|||
|
|
|
|||
|
|
int main(int argc, char *argv[])
|
|||
|
|
{
|
|||
|
|
QApplication a(argc, argv);
|
|||
|
|
|
|||
|
|
// 设置应用程序图标
|
|||
|
|
a.setWindowIcon(QIcon(":/common/resource/logo.png"));
|
|||
|
|
|
|||
|
|
// 使用 SingleInstanceManager 检查单例
|
|||
|
|
SingleInstanceManager instanceManager(
|
|||
|
|
QStringLiteral("%1_SingleInstance_Key").arg(STATORWORKPIECEPOSITION_APP_KEY));
|
|||
|
|
|
|||
|
|
if (instanceManager.isAnotherInstanceRunning()) {
|
|||
|
|
// 已有实例在运行,显示提示信息并退出
|
|||
|
|
QMessageBox::information(nullptr,
|
|||
|
|
QObject::tr("应用程序已运行"),
|
|||
|
|
QObject::tr("%1应用程序已经在运行中,请勿重复启动!")
|
|||
|
|
.arg(QString::fromUtf8(STATORWORKPIECEPOSITION_APP_NAME)),
|
|||
|
|
QMessageBox::Ok);
|
|||
|
|
return 0;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
// 检查授权,无授权则显示授权对话框
|
|||
|
|
if (!AuthView::CheckAndShow(nullptr)) {
|
|||
|
|
// 用户取消授权或授权失败,退出程序
|
|||
|
|
return 0;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
// 没有其他实例运行,正常启动应用程序
|
|||
|
|
MainWindow w;
|
|||
|
|
w.show();
|
|||
|
|
|
|||
|
|
return a.exec();
|
|||
|
|
}
|