Getting line code from qdebug
-
To trolls: may i suggest you to add to qdebug the number of line where it is called, please?
1Main {
2 qdebug()<<"number: ";
3}
Output:
Number 2 -
The C++ standard defines the macro name <code>_ _ LINE _ _</code>, which expands to the line number of the current source line.
@
qDebug() << "number: " << LINE;
@And please change your topic title to something reasonable. Thanks.
-
Wow, I see why you are Area 51 Engineer...
Thank you for this tip.BR,
-
There is a big discussion on that very subject on development mailing list. Here's a link to a pretty much random post (the talk is really long, you'll have to read it anyway to get to know what was decided): "link":http://lists.qt-project.org/pipermail/development/2012-February/001789.html.
Idea is to expand logging a lot more than just the line number.
-
there are a couple of more "standard makros":http://gcc.gnu.org/onlinedocs/cpp/Standard-Predefined-Macros.html to be of use
-
[quote author="sierdzio" date="1328799835"]There is a big discussion on that very subject on development mailing list. Here's a link to a pretty much random post (the talk is really long, you'll have to read it anyway to get to know what was decided): "link":http://lists.qt-project.org/pipermail/development/2012-February/001789.html.
Idea is to expand logging a lot more than just the line number.[/quote]
Thanks for the link - todays bedtime story.
-
What about if i want to get the same output from the following?
@
Write(qstring msg) { qdebug()<<msg;Main(){
Write("bla");
}
@ -
I don't think that's possible, as the macro always expands to the current line. But you might use the preprocessor to simulate the behaviour.
@
#define write(msg) writeLine(LINE, msg)void writeLine(int line, QString msg)
{
qDebug() << line << msg;
}...
write("message"); // 9 "message"
@