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

QStringLiteral broken for unicode characters

    XMLWordPrintable

Details

    • Bug
    • Resolution: Out of scope
    • Not Evaluated
    • None
    • 5.12.0
    • None
    • Microsoft Visual Studio Community 2017
      Version 15.9.5
    • Windows

    Description

      I am trying to do something like this:

      QString str = QStringLiteral("Some international text");
      QFile file("C:/Some/File");
      file.open(QIODevice::WriteOnly);
      file.write(str.toUtf8());
      

      I expect the international text to be written UTF-8 encoded. Instead, it gets written in some broken encoding. My source files are UTF-8 without BOM, though I am using the "/utf-8" MSVC command line switch, so the absence of BOM shouldn't matter.

      Looking at the implementation of QStringLiteral, the problem seems to be the following:

      #define QT_UNICODE_LITERAL(str) u"" str
      

      Changing it to look like this seems to fix the problem.

      #define QT_UNICODE_LITERAL(str) u ## str
      

      Attachments

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

        Activity

          People

            thiago Thiago Macieira
            jart Joseph Artsimovich
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes