Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

Subclassing QDebug to get rid of the NewLine of QDebug() function ?



  • Does anyone here have even tried to subclass QDebug in a way that it does not send a Line Feel (“\n”) when it is destroyed? Is there a virtual function to reimplement in order to easily do it.
    Thanks in advance
    Gilles
    PS : I know I could use std::cout, but it does not display Qt Classes


  • Moderators

    Instead of subclassing QDebug you can call qInstallMsgHandler(someHandlerFunc) and then chop the offending newline character in this handler and output it to wherever you want.

    This way you have full control over what and where is outputted but you get to keep the nice QDebug formatting.

    http://doc.qt.digia.com/qt/qtglobal.html#qInstallMsgHandler



  • Thanks Krzystof. That's exactly what i needed.
    Adding in the message handler this :
    @
    case QtDebugMsg:
    std::cout << msg;
    break;
    @

    gave me the behavior i was looking for.


Log in to reply