Results 1 to 3 of 3

Thread: Special characters in strings stored in a QStringList

  1. #1
    Join Date
    Jul 2011
    Location
    Paris
    Posts
    31
    Thanks
    5
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Special characters in strings stored in a QStringList

    Hello,

    I have an application that gets a list of names from a text file and store those names in a QStringList. Afterwards, I use that list to access certain items of a QHash that have the names stored in my QStringList as their keys. The problem I am having is that some of the names might have special characters such as é, à , ù, etc.

    So when this is the case I realized that when a name such as "Jérémy" for example, this name gets stored in the QStringList as "J?r?my" so when I want to access the item which has as key "Jérémy", my QHash it doesn't find the item.

    How can I make the QStringList store the names with special characters correctly ? When reading from the text file to the QStringList I am doing:

    Qt Code:
    1. QFile file(name);
    2. file.open(QIODevice::ReadOnly | QIODevice::Text);
    3.  
    4. QTextStream in(&file);
    5. in.setCodec("UTF-8");
    6.  
    7. // then in a loop while not at the end of the text file..
    8. QString line = in.readLine();
    9. myStrList.append(line);
    To copy to clipboard, switch view to plain text mode 


    Appreciate any help! Thanks.

  2. #2
    Join Date
    Mar 2008
    Location
    Kraków, Poland
    Posts
    1,536
    Thanked 284 Times in 279 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Special characters in strings stored in a QStringList

    Are You sure that codec UTF-8 is correct ? Maybe this file is in some 8-bit local codec ?
    QStringList have nothing to this problem.

  3. #3
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Special characters in strings stored in a QStringList

    Does "line" in line #8 contain a correctly decoded string? Please verify the string and not its output to the console using qDebug.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


Similar Threads

  1. Remap special characters?
    By PaladinKnight in forum Qt Programming
    Replies: 0
    Last Post: 28th September 2010, 07:23
  2. special characters in xml
    By khcbabu in forum Qt Programming
    Replies: 3
    Last Post: 6th November 2008, 23:10
  3. QtXml and special characters
    By supergillis in forum Qt Programming
    Replies: 4
    Last Post: 29th September 2008, 18:44
  4. QT 4 Xml parsing with special characters
    By KrishnaKishan in forum Qt Programming
    Replies: 1
    Last Post: 18th June 2007, 11:53
  5. Using special characters in QT dialogs
    By hvengel in forum Qt Tools
    Replies: 2
    Last Post: 10th April 2007, 01:32

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.