Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

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

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

1 Answer

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...