Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
988 views
in Technique[技术] by (71.8m points)

qt - qDebug not showing __FILE__,__LINE__

According to qlogging.h

#define qDebug QMessageLogger(__FILE__, __LINE__, Q_FUNC_INFO).debug

but when I use like this, file,line,function name not show.

qDebug()<< "abc"; // only show abc;
qDebug()<< "";    // show nothing;

I search for a while, it seems no one had my problem like above.

I use ubuntu14.04,g++ version 4.8.2, qt5.3 build from git.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

You can reformat from default output format. This function was introduced in Qt 5.0.

The line number does not output because the default message pattern is "%{if-category}%{category}: %{endif}%{message}". This format means that the default outputting format is not including metadata like a line number or file name.

% cat logtest.pro

TEMPLATE = app
TARGET = logtest
mac:CONFIG-=app_bundle
SOURCES += main.cpp

% cat main.cpp

#include <QCoreApplication>
#include <QDebug>

int main(int argc, char *argv[])
{
    qSetMessagePattern("%{file}(%{line}): %{message}");
    QCoreApplication a(argc, argv);
    qDebug() << "my output";
    return 0;
}

% qmake && make

% ./logtest

main.cpp(8): my output

You can also use QT_MESSAGE_PATTERN environment variable for setting the message pattern without calling qSetMessagePattern().

See reference for other placeholder. http://qt-project.org/doc/qt-5/qtglobal.html#qSetMessagePattern


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...