Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-36915

Clarify use of qPrintable together with qDebug and friends (toLocal8Bit() vs utf8)

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: P2: Important P2: Important
    • None
    • 5.2.1
    • Core: I/O

      qPrintable() is defined as "str.toLocal8Bit().constData()". One of it's main uses (also documented) is actually to allow printing of QStrings in qDebug statements, e..g

      qWarning("%s: %s", qPrintable(key), qPrintable(value));
      

      However, qWarning in the end uses QString::vsnprintf() to format it's output, which - according to the documentation of QString::sprintf() - expects "UTF-8 string for %s and Latin-1 string for the format string". The QDebug::operator<< for const char * also uses QString::fromUtf8(t).

      I suppose we can

      • fix QDebug, qt_message to expect local 8 bit encoding for const char *.
      • deprecate the use of qPrintable in combination with qDebug.
      • redefine qPrintable to str.toUtf8().constData(), and break it for people using it for system printf()/cout.

        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

            kkohne Kai Köhne
            kkohne Kai Köhne
            Votes:
            0 Vote for this issue
            Watchers:
            7 Start watching this issue

              Created:
              Updated:
              Resolved:

                There are no open Gerrit changes