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. Most convenient way from qDebug to log...
Forum Update on Monday, May 27th 2025

Most convenient way from qDebug to log...

Scheduled Pinned Locked Moved Solved General and Desktop
2 Posts 2 Posters 164 Views
  • 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.
  • M Offline
    M Offline
    Merlino
    wrote on last edited by
    #1

    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();
    m_myLog.logInformation(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.

    1 Reply Last reply
    0
    • sierdzioS Offline
      sierdzioS Offline
      sierdzio
      Moderators
      wrote on last edited by
      #2

      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.

      (Z(:^

      1 Reply Last reply
      3

      • Login

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