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 Updated to NodeBB v4.3 + New Features

Most convenient way from qDebug to log...

Scheduled Pinned Locked Moved Solved General and Desktop
2 Posts 2 Posters 167 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.
  • M Offline
    M Offline
    Merlino
    wrote on 3 Oct 2020, 11:11 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
    • S Offline
      S Offline
      sierdzio
      Moderators
      wrote on 3 Oct 2020, 13:01 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

      2/2

      3 Oct 2020, 13:01

      • Login

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