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

QString toStdString() does not convert correctly if using special characters

    XMLWordPrintable

Details

    • Bug
    • Resolution: Invalid
    • P2: Important
    • None
    • 5.2.1
    • None
    • Windows7

    Description

      Here is a peace of code that used to work with 4.7.4 and fails with 5.2.1:

      QString folder = QFileDialog::getExistingDirectory( NULL, "", "" );
      std::string filename = folder.toStdString() + "/file.txt";
      std::fstream file;
      file.open( (char*) filename.c_str(), ios_base::out );
      assert( file.is_open() );

      If you make "folder" point to a folder containing special characters (é, à, ù...), then QString::toStdString fails to return a valid std::string. Qt 4.7.4 used to work because toAScii() was invoked. Qt 5.2.1 fails because it uses toUtf8().

      One may workaround the problem by calling toLatin1() rather that toStdString(), but I would say toStdString() is supposed to work smartly as it used to (and moeroevr, I use it in tones of places and don't really want to update them all to migrate my code from 4.7.4 to 5.2.1....).

      Attachments

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

        Activity

          People

            thiago Thiago Macieira
            jpo38 Jean Porcherot
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes