Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. qDebug messages not showing in console window with qInstallMessageHandler implemented
Forum Updated to NodeBB v4.3 + New Features

qDebug messages not showing in console window with qInstallMessageHandler implemented

Scheduled Pinned Locked Moved Unsolved General and Desktop
2 Posts 2 Posters 387 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • J Offline
    J Offline
    jenschucksgs
    wrote on last edited by
    #1

    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?

    1 Reply Last reply
    0
    • Christian EhrlicherC Offline
      Christian EhrlicherC Offline
      Christian Ehrlicher
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Works fine for me with Qt5.15.2. Are you sure e.g. QT_NO_DEBUG_OUTPUT is not set in your setup somewhere?

      Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
      Visit the Qt Academy at https://academy.qt.io/catalog

      1 Reply Last reply
      1

      • Login

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • Users
      • Groups
      • Search
      • Get Qt Extensions
      • Unsolved