ThinkChat🤖让你学习和工作更高效,注册即送10W Token,即刻开启你的AI之旅 广告
[TOC] ## 概述 允许改变qDebug()、qWarning()、qCritical()、qFatal()的输出格式 两种方式 1. 修改环境变量 ``` QT_MESSAGE_PATTERN="[%{time yyyyMMdd h:mm:ss.zzz t} %{if-debug}D%{endif}%{if-info}I%{endif}%{if-warning}W%{endif}%{if-critical}C%{endif}%{if-fatal}F%{endif}] %{file}:%{line} - %{message}" ``` 2. 设置 qSetMessagePattern 函数 > 环境变量优先 ## 示例 ``` qSetMessagePattern("[%{time yy-MM-dd h:mm:ss.z} %{type}] %{message} [%{file}:%{line}] "); qInfo()<<"测试"; // Debug: 测试 (../hello3/main.cpp:38, int main(int, char **)) qDebug()<<"测试"; // Debug: 测试 (../hello3/main.cpp:38, int main(int, char **)) ``` output ``` [21-10-29 22:16:08.196 info] 测试 [../hello3/main.cpp:74] [21-10-29 22:16:08.196 debug] 测试 [../hello3/main.cpp:75] [21-10-29 22:16:08.27 critical] "docx File" [../hello3/mainwindow.cpp:29] ```