Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Qt 5.4 - QT_MESSAGELOGCONTEXT

Tags:

qt

Switching from Qt 5.3 to 5.4, suddenly my custom message handler is receiving neither the line number nor file name from Qt libraries that use qDebug(), qWarning() and qCritical().

The docs indicate that this was a change in Qt 5.4. To get this information you have to explicitly define QT_MESSAGELOGCONTEXT. So I did. I downloaded the Qt 5.4 source code, configured it, compiled it, and set my code to use the new libraries. The problem is, I'm still not getting the file name and line number info.

Here's how I'm configuring the Qt build:

configure.bat -platform win32-msvc2010 -debug-and-release -nomake examples -nomake tests -opensource -opengl desktop -c++11 -no-strip -D QT_MESSAGELOGCONTEXT
like image 250
mjk99 Avatar asked Feb 04 '15 21:02

mjk99


1 Answers

You don't need to rebuild Qt with that define, you need to build your application with that define enabled.

The rationale behind the behaviour change is quite simple: you may not want sensitive information (function names, line numbers) to be leaked in debug or warning outputs that your application may have.

Therefore, by default, in release builds the function names and line numbers are wiped out. On the other hand, they're still available in debug builds, so you may actually avoid using that define and simply recompile your app in debug mode.


If you want to enable function names and line numbers even for release builds, open the .pro file of your application and add something like

DEFINES += QT_MESSAGELOGCONTEXT

Then rerun qmake and rebuild the entire app.

like image 119
peppe Avatar answered Dec 08 '22 15:12

peppe