Preserve 'line' and 'file' macro expansion when in release mode
-
I installed my own message handler to use qDebug(), qInfo(), etc as "logging" tool. The second argument passed to the handler store the message context, such as file, function, line, thread pid, etc. They work well under debug mode, and the line and file information printed as expected. But when compiled in release mode, all line and file information are gone (the 'file' and 'line' in QMessageLogContext is 0). It seems the macro
QT_NO_DEBUG
prevents these infos. But I don't want to removeQT_NO_DEBUG
, because I need this macro to prevent other debug macros expansion, such asQ_ASSERT()
,Q_ASSERT_X()
. I just need the "file", "line" or the "function" information in QMessageLogContext. Any method to achieve this?Thanks.
-
-
Add this to your .pro
CONFIG(release,debug|release) { # active log context pour Application::ErrorMessageLog() en mode release DEFINES += QT_MESSAGELOGCONTEXT }
Maybe you need to clear/rebuild your project.
before:
28-03-2018 15:32:53.285 [MultiDocsDemo from ???] error !
now:
28-03-2018 15:36:53.940 [MultiDocsDemo from openNewWindow() in Application.cpp line 1434] error !