2025-08-24 23:24:33 +08:00
|
|
|
#include "mainwindow.h"
|
2025-09-29 00:56:53 +08:00
|
|
|
#include "IStatusUpdate.h"
|
|
|
|
|
#include "IVrBeltTearingConfig.h"
|
|
|
|
|
#include "widgets/TearingDataTableWidget.h"
|
2025-10-12 16:46:46 +08:00
|
|
|
#include "CrashHandler.h"
|
2025-08-24 23:24:33 +08:00
|
|
|
|
|
|
|
|
#include <QApplication>
|
2025-09-24 22:36:13 +08:00
|
|
|
#include <QMetaType>
|
|
|
|
|
#include <QVector>
|
|
|
|
|
#include <QList>
|
|
|
|
|
#include <QPersistentModelIndex>
|
|
|
|
|
#include <QAbstractItemModel>
|
2025-10-12 16:46:46 +08:00
|
|
|
#include <QSharedMemory>
|
|
|
|
|
#include <QSystemSemaphore>
|
|
|
|
|
#include <QMessageBox>
|
|
|
|
|
#include <QStandardPaths>
|
|
|
|
|
#include <QDir>
|
2025-08-24 23:24:33 +08:00
|
|
|
|
2025-11-19 00:23:09 +08:00
|
|
|
#include "Version.h"
|
|
|
|
|
|
2025-08-24 23:24:33 +08:00
|
|
|
int main(int argc, char *argv[])
|
|
|
|
|
{
|
2025-10-12 16:46:46 +08:00
|
|
|
// 初始化崩溃处理程序
|
|
|
|
|
// CrashHandler::setDumpPath("c:/crash_dumps");
|
|
|
|
|
// CrashHandler::registerCrashHandler();
|
|
|
|
|
|
2025-08-24 23:24:33 +08:00
|
|
|
QApplication a(argc, argv);
|
2025-11-19 00:23:09 +08:00
|
|
|
|
|
|
|
|
// 设置应用程序信息
|
|
|
|
|
a.setApplicationName(BELT_TEARING_APP_PRODUCT_NAME);
|
|
|
|
|
a.setApplicationVersion(BELT_TEARING_APP_VERSION_STRING);
|
|
|
|
|
a.setOrganizationName(BELT_TEARING_APP_PRODUCT_NAME);
|
2025-09-24 22:36:13 +08:00
|
|
|
|
|
|
|
|
// Register meta types for signal-slot connections
|
|
|
|
|
qRegisterMetaType<QVector<int>>("QVector<int>");
|
|
|
|
|
qRegisterMetaType<QList<QPersistentModelIndex>>("QList<QPersistentModelIndex>");
|
|
|
|
|
qRegisterMetaType<QAbstractItemModel::LayoutChangeHint>("QAbstractItemModel::LayoutChangeHint");
|
2025-10-08 21:45:37 +08:00
|
|
|
qRegisterMetaType<Qt::SortOrder>("Qt::SortOrder");
|
2025-09-24 22:36:13 +08:00
|
|
|
|
2025-09-29 00:56:53 +08:00
|
|
|
// Register custom meta types for BeltTearing
|
|
|
|
|
qRegisterMetaType<TearingData>("TearingData");
|
|
|
|
|
qRegisterMetaType<BeltTearingWorkStatus>("BeltTearingWorkStatus");
|
|
|
|
|
qRegisterMetaType<BeltTearingResult>("BeltTearingResult");
|
|
|
|
|
qRegisterMetaType<ServerInfo>("ServerInfo");
|
|
|
|
|
qRegisterMetaType<BeltTearingParam>("BeltTearingParam");
|
|
|
|
|
qRegisterMetaType<BeltTearingConfigResult>("BeltTearingConfigResult");
|
|
|
|
|
qRegisterMetaType<NumericTableWidgetItem>("NumericTableWidgetItem");
|
|
|
|
|
|
2025-10-12 16:46:46 +08:00
|
|
|
|
|
|
|
|
// 使用应用程序名称作为唯一标识符
|
|
|
|
|
const QString appKey = "BeltTearingApp_SingleInstance_Key";
|
|
|
|
|
|
|
|
|
|
// 创建系统信号量,用于同步访问共享内存
|
|
|
|
|
QSystemSemaphore semaphore(appKey + "_semaphore", 1);
|
|
|
|
|
semaphore.acquire(); // 获取信号量
|
|
|
|
|
|
|
|
|
|
// 创建共享内存对象
|
|
|
|
|
QSharedMemory sharedMemory(appKey + "_memory");
|
|
|
|
|
|
|
|
|
|
bool isRunning = false;
|
|
|
|
|
|
|
|
|
|
// 尝试附加到现有的共享内存
|
|
|
|
|
if (sharedMemory.attach()) {
|
|
|
|
|
// 如果能够附加,说明已有实例在运行
|
|
|
|
|
isRunning = true;
|
|
|
|
|
} else {
|
|
|
|
|
// 尝试创建新的共享内存
|
|
|
|
|
if (!sharedMemory.create(1)) {
|
|
|
|
|
// 创建失败,可能是因为已经存在
|
|
|
|
|
qDebug() << "Unable to create shared memory segment:" << sharedMemory.errorString();
|
|
|
|
|
isRunning = true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
semaphore.release(); // 释放信号量
|
|
|
|
|
|
|
|
|
|
if (isRunning) {
|
|
|
|
|
// 已有实例在运行,显示提示信息并退出
|
|
|
|
|
QMessageBox::information(nullptr,
|
|
|
|
|
QObject::tr("应用程序已运行"),
|
|
|
|
|
QObject::tr("撕裂应用程序已经在运行中,请勿重复启动!"),
|
|
|
|
|
QMessageBox::Ok);
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2025-08-24 23:24:33 +08:00
|
|
|
MainWindow w;
|
|
|
|
|
w.show();
|
|
|
|
|
return a.exec();
|
|
|
|
|
}
|