受文章 http://blog.youkuaiyun.com/foruok/article/details/40656285 的启发,找到另外一种更好的方法,不用每次建工程后到project里面去设置
在main函数入口加入
qSetMessagePattern(" Loc:[%{file}:%{line}]%{message}");//注意Loc前面有三个空格,参考:http://woboq.com/blog/nice-debug-output-with-qt.html
可以显示打印信息的行号等。
具体其他占位符可以参考
http://doc.qt.io/qt-5/qtglobal.html#qSetMessagePattern
ps:如果只有debug下才能打印C++文件中message对应的行号等,Release下需要调整qloging.h文件中关于QT_MESSAGELOG_FILE等的宏定义(参考Debug模式修改)