Important: Please read the Qt Code of Conduct -

Most convenient way from qDebug to log...

  • Hello!
    I need to add a persistent log to my app. My idea is to transform the qDebug calls:

    qDebug << "blablablablablabla " << variable1 << "blablabla" << variable2;

    in this:

    logInformation() << "blablablablablabla " << variable1 << "blablabla" << variable2;

    that should do this:

    QTextSream textStream;
    textStream << "blablablablablabla " << variable1 << "blablabla" << variable2;
    qDebug << textStream.readAll();

    Which is the most convenient way to do the transformation with the less effort, in your opinion?

    I would have thought of doing a sort of subclassing of the QDebug class, going to redefine some methods / operators, to obtain the same form of call. I don't know if it's feasible, I'm still thinking about it.

  • Moderators

    You should install custom log handler instead: qInstallMessageHandler.

    This gives you full control over all logs, without any need to change existing calls - you can still use qDebug(), qWarning() etc.

Log in to reply