qDebug messages not showing in console window with qInstallMessageHandler implemented
-
My source code file:
#include <QCoreApplication> #include <QtDebug> #include <QtGlobal> #include <stdio.h> #include <stdlib.h> void myMessageOutput(QtMsgType type, const QMessageLogContext &context, const QString &msg) { QByteArray localMsg = msg.toLocal8Bit(); fprintf(stderr, "MESSAGE (%s:%u %s): %s\n", context.file, context.line, context.function, localMsg.constData()); fflush(stderr); } int main(int argc, char **argv) { QCoreApplication app(argc, argv); qInstallMessageHandler(myMessageOutput); qDebug() << "Printed in the console"; qInstallMessageHandler(0); qDebug() << "Also printed in the console"; return app.exec(); }
My CMakeLists.txt file:
cmake_minimum_required( VERSION 3.10 ) SET( BIN_NAME test_debug ) INCLUDE( ../../cyflex_qt.cmake OPTIONAL ) project( "${BIN_NAME}" ) find_package(Qt5 REQUIRED COMPONENTS Core Widgets ) set( CMAKE_INCLUDE_CURRENT_DIR ON ) set( CMAKE_AUTOMOC ON ) set( CMAKE_AUTOUIC ON ) set( CMAKE_BINARY_OUTPUT_DIRECTORY ${TARGET_BINPATH} ) SET( ${BIN_NAME}_SOURCES main.cpp ) add_executable( ${BIN_NAME} ${${BIN_NAME}_SOURCES} ) target_link_libraries(${BIN_NAME} Qt5::Widgets )
We have migrated our code from Scientific Linux (32bit) to Oracle Linux (64bit). When I run this exact code on my 32bit system in qt5, I get the qDebug messages at the console as I expect. When I run this code on my 64bit system in qt5, no messages get displayed.
If I create a ~/.config/QtProject/qtlogging.ini file on my 64bit system. The debug messages are printed to the console. However, for a GUI application, there are many debug messages printed besides the expected ones.
Example ~/.config/QtProject/qtlogging.ini
[Rules] *.debug=true
How do I only get the expected qDebug statements written to the console? Is there something I need to do without creating the qtlogging.ini file?
-
Works fine for me with Qt5.15.2. Are you sure e.g. QT_NO_DEBUG_OUTPUT is not set in your setup somewhere?