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. QDebug "breaks" outputting a char with value 0?
QtWS25 Last Chance

QDebug "breaks" outputting a char with value 0?

Scheduled Pinned Locked Moved General and Desktop
4 Posts 3 Posters 1.3k 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.
  • U Offline
    U Offline
    utcenter
    wrote on last edited by
    #1

    Care to guess what would the output of this code be?

    @ char c = 0;
    for (int i = 0; i < 4; ++i) qDebug() << c << i << endl;@

    A hint - there is no output... as of why, it will be nice if someone briefly explains the internals of qDebug and what is the reason for this behavior...

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

      Just a quick thinking: c becomes the ascii character 0 which is invisible ?

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      0
      • U Offline
        U Offline
        utcenter
        wrote on last edited by
        #3

        Yes, if you use std::cout or QTextStream you will get an invisible character for c, but you will also get i and endl, while with qDebug the entire chain is terminated when the 0 char is reached so an invisible character is not being output, nor any of the stuff that follows.

        1 Reply Last reply
        0
        • D Offline
          D Offline
          dbzhang800
          wrote on last edited by
          #4

          First, QTextStream is used to generate a QString.
          Then, this string get output by following line.

          @
          fprintf(stderr, "%s", logMessage.toLocal8Bit().constData())
          @

          Consider that the first Char of the logMessage is '\0', so the length of the C string const char * will be zero. Though the length of the QString is not zero.

          1 Reply Last reply
          0

          • Login

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