打印到Qt Creator的调试控制台时,可以使__FILE__和__LINE__可链接吗? [英] Can __FILE__ and __LINE__ be made linkable when printed to Qt Creator's debug console?
问题描述
标题:
#define TRACE_ERROR(s) \
{
...
char TraceBuffer[512];
sprintf(TraceBuffer, "%s\t(%s:%d)", s, __FILE__, __LINE__);
DebugErrTrace(TraceBuffer);
...
}
实施:
void DebugErrTrace(char *String, ...) {
...
qDebug() << String;
}
上面显示了一行调试跟踪,看起来可能像
The above spits out a line of debug trace, which might look something like
错误文件丢失! (..\trunk\Common\FileManager.cpp:102)
在Qt Creator的调试控制台中。
in Qt Creator's debug console.
我注意到Qt自己的错误消息,例如
I've noticed that Qt's own error messages e.g.
Object :: connect:没有这样的插槽cClass ..\trunk\Components\Class.cpp中的:: Method(QString):301
创建类似于超链接的内容在调试行的 __ FILE __:__ LINE __
部分附近,链接到引起问题的行。我可以用自己的调试输出来执行此操作吗?
create what looks like a hyperlink around the __FILE__:__LINE__
part of the debug line, linking to the line which caused the problem. Is there any way I can I do this with my own debug output?
干杯,山姆
推荐答案
根据Qt Creator源代码(有),则仅为符合以下正则表达式的行创建超链接:
According to Qt Creator source code (there), the hyperlinks are only created for lines matching these regular expressions:
"^(?:\\[Qt Message\\] )?(file:///.+:\\d+(?::\\d+)?):"
"Object::.*in (.*:\\d+)"
"ASSERT: .* in file (.+, line \\d+)"
"^ Loc: \\[(.*)\\]"
所以您可以构造出最简单的线条像这样:
So the simplest lines you could construct look like this:
qWarning("file:///%s:%i: %s", __FILE__, __LINE__, "your message");
qWarning(" Loc: [%s:%i] %s", __FILE__, __LINE__, "your message");
Qt Creator似乎并不关心文件之后的路径: ///
是否绝对。
Qt Creator doesn't seem to care if the path after "file:///"
is absolute or not.
这篇关于打印到Qt Creator的调试控制台时,可以使__FILE__和__LINE__可链接吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!