QMessageLogContext 的字段(如:文件、函数、行)为空或为零

QMessageLogContext's fields (like: file, function, line) empty or zero

我有 2 台机器 Debian 7.8 64/32 位。我创建了一个简单的程序。在 main.cpp:

void action(QtMsgType type, const QMessageLogContext &context, const QString &msg)
{
    static QFile logFile("logfile.log");
    static QTextStream ts(&logFile);
    if(logFile.open(QFile::ReadWrite | QFile::Append))
    {
      ts << context.file << ":" << context.line << ":"
         << context.function << ": " << msg << endl;
      logFile.close();
    }
}

int main(int argc, char* argv[])
{
    QCoreApplication app(argc, argv);
    qInstallMessageHandler(action);
    qDebug() << "this is some log";
    return app.exec();
}

在"logfile.log"我必须看到:

main.cpp:30:int main(int, char**): this is some log 

但在 Debian 7.8 64 位 Qt 5.4.1 GCC 4.6.1 64 位上我只看到:

:0:: this is some log 

我还在 Debian 7.8 32 位 Qt 5.3.1 GCC 4.6.1 32 位上进行了测试。运行良好。
它是 Qt 5.4.1(64 位)的错误吗?或者我错过了什么?
你能帮帮我吗?

很可能,您正在使用发布版本。默认情况下,Qt 不会在发布模式下填充这些字段。您可以覆盖它并通过定义 QT_MESSAGELOGCONTEXT 启用上下文日志记录,如 .

中所述