From 95a8067342ebdd85a80ce278c351d93d97008f46 Mon Sep 17 00:00:00 2001 From: Your Name Date: Sun, 17 May 2026 14:19:39 +0800 Subject: [PATCH] =?UTF-8?q?modify:=E4=BF=AE=E6=94=B9linux=E4=B8=8B?= =?UTF-8?q?=E7=9A=84=E6=97=A5=E5=BF=97=E7=9B=AE=E5=BD=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- loghandler.cpp | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/loghandler.cpp b/loghandler.cpp index 8435581..b1a8dc2 100644 --- a/loghandler.cpp +++ b/loghandler.cpp @@ -78,6 +78,25 @@ void messageHandler(QtMsgType type, const QMessageLogContext &context, const QSt } } +static QString LinuxRuntimeRoot() +{ +#ifdef Q_OS_LINUX + QByteArray root = qgetenv("LC_APP_ROOT"); + if(!root.isEmpty()) + { + return QDir::cleanPath(QString::fromLocal8Bit(root)); + } + + QByteArray appImage = qgetenv("APPIMAGE"); + if(!appImage.isEmpty()) + { + return QFileInfo(QString::fromLocal8Bit(appImage)).absolutePath(); + } +#endif + + return QCoreApplication::applicationDirPath(); +} + // 给Qt安装消息处理函数 void LogHandler::installMessageHandler() { @@ -89,7 +108,12 @@ void LogHandler::installMessageHandler() auto _currentDate = QDateTime::currentDateTime().toString("yyyy-MM-dd"); //打开/创建文件 +#ifdef Q_OS_LINUX + auto _appDirPath = LinuxRuntimeRoot(); +#else auto _appDirPath = QCoreApplication::applicationDirPath(); +#endif + auto _logDirPath = _appDirPath + "/logs/"; QDir _logDir(_logDirPath); if(!_logDir.exists())