diff --git a/CMakeLists.txt b/CMakeLists.txt index 23bd149..1905c17 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -145,10 +145,10 @@ install(DIRECTORY ${CMAKE_SOURCE_DIR}/bin/platforms/ set(CPACK_PACKAGE_NAME "Viewer") set(CPACK_PACKAGE_VENDOR "Lorenzo Zhao") set(CPACK_PACKAGE_DESCRIPTION_SUMMARY "Depth Camera Control System") -set(CPACK_PACKAGE_VERSION "0.3.2") +set(CPACK_PACKAGE_VERSION "0.3.3") set(CPACK_PACKAGE_VERSION_MAJOR "0") set(CPACK_PACKAGE_VERSION_MINOR "3") -set(CPACK_PACKAGE_VERSION_PATCH "2") +set(CPACK_PACKAGE_VERSION_PATCH "3") set(CPACK_PACKAGE_INSTALL_DIRECTORY "Viewer") # WiX生成器配置(用于MSI) diff --git a/README.md b/README.md index 9362a98..c21aebc 100644 --- a/README.md +++ b/README.md @@ -283,4 +283,4 @@ d330viewer/ - 使用Qt6信号槽机制进行模块间通信 - OpenCL kernel代码内联在C++源文件中 - 配置使用QSettings持久化 -- 日志输出到 `bin/d330viewer.log` +- 日志输出到 `%LOCALAPPDATA%/Viewer/Viewer/viewer.log`(例如 `C:/Users/<用户名>/AppData/Local/Viewer/Viewer/viewer.log`) diff --git a/src/main.cpp b/src/main.cpp index d0c250f..40a3063 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1,12 +1,15 @@ #include #include #include +#include + #include "gui/MainWindow.h" #include "core/Logger.h" -// Custom message handler to redirect qDebug output to Logger +// Redirect Qt log output to file logger. void messageHandler(QtMsgType type, const QMessageLogContext &context, const QString &msg) { + Q_UNUSED(context); Logger *logger = Logger::instance(); switch (type) { @@ -30,27 +33,30 @@ int main(int argc, char *argv[]) { QApplication app(argc, argv); - // 设置应用程序信息 app.setOrganizationName("Viewer"); app.setApplicationName("Viewer"); - app.setApplicationVersion("0.3.2"); + app.setApplicationVersion("0.3.3"); - // 初始化Logger(在可执行文件同目录下) - QString logPath = QCoreApplication::applicationDirPath() + "/viewer.log"; + // Prefer LocalAppData so MSI installs under Program Files can always write logs. + QString logDir = QStandardPaths::writableLocation(QStandardPaths::AppLocalDataLocation); + if (logDir.isEmpty()) { + logDir = QCoreApplication::applicationDirPath(); + } + QDir().mkpath(logDir); + + const QString logPath = QDir(logDir).filePath("viewer.log"); Logger::instance()->setLogFile(logPath); - Logger::instance()->setMaxLines(10000); // 保留最新10000行 + Logger::instance()->setMaxLines(10000); - // 安装消息处理器 qInstallMessageHandler(messageHandler); qDebug() << "Viewer started"; qDebug() << "Log file:" << logPath; - // 创建并显示主窗口 MainWindow mainWindow; mainWindow.show(); - int result = app.exec(); + const int result = app.exec(); qDebug() << "Viewer exiting";