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

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

    XMLWordPrintable

Details

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

    Description

      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.

      Attachments

        Issue Links

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

          Activity

            People

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

              Dates

                Created:
                Updated:
                Resolved:

                Gerrit Reviews

                  There are no open Gerrit changes