2026-03-28 10:49:55 +08:00

66 lines
1.7 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 "StyledMessageBox.h"
#include <QObject>
#include <QTextCodec>
#include "VrLog.h"
#include "AuthView.h"
#ifdef _WIN32
#include <windows.h>
#include <cstdio>
#endif
#ifdef _WIN32
// Windows平台特定设置解决中文乱码问题
void setupWindowsConsoleEncoding() {
// 设置控制台代码页为UTF-8
SetConsoleOutputCP(CP_UTF8);
SetConsoleCP(CP_UTF8);
}
#endif
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
#ifdef _WIN32
// Windows平台特定设置解决中文乱码问题
setupWindowsConsoleEncoding();
#endif
#if (QT_VERSION < QT_VERSION_CHECK(5, 0, 0))
// Qt4及更早版本需要显式设置编码
QTextCodec *codec = QTextCodec::codecForName("UTF-8");
QTextCodec::setCodecForLocale(codec);
#endif
// 设置应用程序图标
a.setWindowIcon(QIcon(":/common/resource/logo.png"));
// 使用 SingleInstanceManager 检查单例
SingleInstanceManager instanceManager("GrabBagApp_SingleInstance_Key");
if (instanceManager.isAnotherInstanceRunning()) {
// 已有实例在运行,显示提示信息并退出
StyledMessageBox::information(nullptr,
QObject::tr("应用程序已运行"),
QObject::tr("编织袋拆垛应用程序已经在运行中,请勿重复启动!"));
return 0;
}
// 检查授权,无授权则显示授权对话框
if (!AuthView::CheckAndShow(nullptr)) {
// 用户取消授权或授权失败,退出程序
return 0;
}
// 没有其他实例运行,正常启动应用程序
MainWindow w;
w.show();
return a.exec();
}