modify:修改linux下的日志目录

This commit is contained in:
Your Name
2026-05-17 14:19:39 +08:00
parent 772cd663ad
commit 95a8067342
+24
View File
@@ -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安装消息处理函数 // 给Qt安装消息处理函数
void LogHandler::installMessageHandler() void LogHandler::installMessageHandler()
{ {
@@ -89,7 +108,12 @@ void LogHandler::installMessageHandler()
auto _currentDate = QDateTime::currentDateTime().toString("yyyy-MM-dd"); auto _currentDate = QDateTime::currentDateTime().toString("yyyy-MM-dd");
//打开/创建文件 //打开/创建文件
#ifdef Q_OS_LINUX
auto _appDirPath = LinuxRuntimeRoot();
#else
auto _appDirPath = QCoreApplication::applicationDirPath(); auto _appDirPath = QCoreApplication::applicationDirPath();
#endif
auto _logDirPath = _appDirPath + "/logs/"; auto _logDirPath = _appDirPath + "/logs/";
QDir _logDir(_logDirPath); QDir _logDir(_logDirPath);
if(!_logDir.exists()) if(!_logDir.exists())