45 lines
1.2 KiB
C++
Raw Permalink 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 "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();
}