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?
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With