Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

qDebug not showing __FILE__,__LINE__

Tags:

qt

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.

like image 250
T_T Avatar asked Jun 03 '14 09:06

T_T


Video Answer


1 Answers

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

like image 195
user1544041 Avatar answered Oct 01 '22 03:10

user1544041