Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

c++

gcc

qt

qt5.4

I have 2 machines Debian 7.8 64/32 bit. I create a simple program. In 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();
}

In the "logfile.log" I must see:

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

but on Debian 7.8 64 bit Qt 5.4.1 GCC 4.6.1 64 bit I just see:

:0:: this is some log 

I also tested on Debian 7.8 32 bit Qt 5.3.1 GCC 4.6.1 32 bit. It runs well.
Is it a bug of Qt 5.4.1 (64 bit)? Or I missed something?
Can you help me?

like image 316
aviit Avatar asked Apr 15 '15 09:04

aviit


1 Answers

Most likely, you are using release build. By default Qt doesn't fill those fields in release mode. You can override this and enable context logging by defining QT_MESSAGELOGCONTEXT as explained in this answer.

like image 126
Pavel Strakhov Avatar answered Nov 03 '22 00:11

Pavel Strakhov