Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. How to implement "\n" in QT QDebug class

How to implement "\n" in QT QDebug class

Scheduled Pinned Locked Moved C / C++ / MFC
tutorialc++debuggingquestion
4 Posts 2 Posters 17 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.
  • L Offline
    L Offline
    Lost User
    wrote on last edited by
    #1

    I am a fan of having code to debug code ratio of 1:99... Here is my most abused debug code example:

    #ifdef MAIN_WINDOW_FLOW
    text = " MainWindow_Serial(QWidget *parent) flow CHART ";
    //text += "m_currentSettings.name";
    //text += m_currentSettings.name;
    text += Q_FUNC_INFO;
    text += QString::number(__LINE__);
    qDebug() << text;
    exit(42);
    qDebug() << text;
    #endif

    I am using QT and been told that "you cannot use (standard ?? ) printf "escape codes " ( I am not sure about correct term here ...) such as \n or \t ..." I am not interested debating ( in QT forum or here ) why QT cannot do that , however, I like to find another way to instruct QString / QDebug to implement these "make it human readable " codes. Any reasonable C++ hacks would be appreciated. Cheers

    K 1 Reply Last reply
    0
    • L Lost User

      I am a fan of having code to debug code ratio of 1:99... Here is my most abused debug code example:

      #ifdef MAIN_WINDOW_FLOW
      text = " MainWindow_Serial(QWidget *parent) flow CHART ";
      //text += "m_currentSettings.name";
      //text += m_currentSettings.name;
      text += Q_FUNC_INFO;
      text += QString::number(__LINE__);
      qDebug() << text;
      exit(42);
      qDebug() << text;
      #endif

      I am using QT and been told that "you cannot use (standard ?? ) printf "escape codes " ( I am not sure about correct term here ...) such as \n or \t ..." I am not interested debating ( in QT forum or here ) why QT cannot do that , however, I like to find another way to instruct QString / QDebug to implement these "make it human readable " codes. Any reasonable C++ hacks would be appreciated. Cheers

      K Offline
      K Offline
      k5054
      wrote on last edited by
      #2

      Have you even looked at the documentation for QDebug? Specifically :

      Quote:

      QDebug &QDebug::operator<<(QChar t) Writes the character, t, to the stream and returns a reference to the stream. Normally, QDebug prints control characters and non-US-ASCII characters as their C escape sequences or their Unicode value (\u1234). To print non-printable characters without transformation, enable the noquote() functionality, but note that some QDebug backends may not be 8-bit clean and may not be able to represent it.

      which leads us to:

      Quote:

      QDebug &QDebug::noquote() Disables automatic insertion of quotation characters around QChar, QString and QByteArray contents and returns a reference to the stream. When quoting is disabled, these types are printed without quotation characters and without escaping of non-printable characters.

      If you need quoted output, its simple enough to do it yourself, just escape the quotes (\") or use Raw literals e.g. std::string hello(R"x("Hello World")x") assigns "Hello World", *including the quote marks" to the variable hello, NB. I have not tried this. I do not use QT. I don't know if this will achieve what you want. I do know how to use google, though. It's more than time enough that you did too.

      Keep Calm and Carry On

      L 1 Reply Last reply
      0
      • K k5054

        Have you even looked at the documentation for QDebug? Specifically :

        Quote:

        QDebug &QDebug::operator<<(QChar t) Writes the character, t, to the stream and returns a reference to the stream. Normally, QDebug prints control characters and non-US-ASCII characters as their C escape sequences or their Unicode value (\u1234). To print non-printable characters without transformation, enable the noquote() functionality, but note that some QDebug backends may not be 8-bit clean and may not be able to represent it.

        which leads us to:

        Quote:

        QDebug &QDebug::noquote() Disables automatic insertion of quotation characters around QChar, QString and QByteArray contents and returns a reference to the stream. When quoting is disabled, these types are printed without quotation characters and without escaping of non-printable characters.

        If you need quoted output, its simple enough to do it yourself, just escape the quotes (\") or use Raw literals e.g. std::string hello(R"x("Hello World")x") assigns "Hello World", *including the quote marks" to the variable hello, NB. I have not tried this. I do not use QT. I don't know if this will achieve what you want. I do know how to use google, though. It's more than time enough that you did too.

        Keep Calm and Carry On

        L Offline
        L Offline
        Lost User
        wrote on last edited by
        #3

        I need time to digest and try your approach. PS I would like to pass this TO YOU (only). In past I did appreciate your help and I am little concerned that you have a caught the "I told you so ...RTFM.. everybody knows that..." disease. Please get well soon... cheers

        L 1 Reply Last reply
        0
        • L Lost User

          I need time to digest and try your approach. PS I would like to pass this TO YOU (only). In past I did appreciate your help and I am little concerned that you have a caught the "I told you so ...RTFM.. everybody knows that..." disease. Please get well soon... cheers

          L Offline
          L Offline
          Lost User
          wrote on last edited by
          #4

          Member 14968771 wrote:

          ..RTFM.. everybody knows that..." disease.

          What a pity you seem immune to it.

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups