Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

qSetMessagePattern("%{file}(%{line}): %{message}") output "unkown(0)"

Tags:

c++

logging

qt

qt5

I'm using qSetMessagePattern to format the output.

The weird thing is even I set %{file} and %{line}, I could only get unknown and 0 in my output. And so does the %{function}. The source and output are below:

qSetMessagePattern("%{file}(%{line}): %{message}");
qDebug() << "msg";

output:

unknown(0): msg

Any ideas? Thanks!

like image 985
Qi W. Avatar asked Apr 09 '26 23:04

Qi W.


2 Answers

Try to add for the target you build:

target_compile_definitions(${PROJECT_NAME} PRIVATE -DQT_DEBUG -DQT_MESSAGELOGCONTEXT)

Seems -DQT_DEBUG has priority when used along with -DQT_NO_DEBUG.

like image 189
Tomilov Anatoliy Avatar answered Apr 12 '26 13:04

Tomilov Anatoliy


add DEFINES += QT_MESSAGELOGCONTEXT to your xxx.pro, and then, rebuild

make clean && make distclean && qmake && make 

I hope this could help you.

like image 27
Jiahao Avatar answered Apr 12 '26 11:04

Jiahao