Results 1 to 4 of 4

Thread: Accented Character

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    May 2010
    Posts
    21
    Thanks
    4
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Accented Character

    Hello everyone.

    I migrated my files (.txt) from Windows (ISO-8859) to Linux (UTF-8).

    Replace command is not recognizing the accented character.

    Qt Code:
    1. QFile file(fileName);
    2. file.open(QIODevice::ReadOnly|QIODevice::Text);
    3. QTextStream in(&file);
    4. QString str = in.readAll().trimmed();
    5. file.close();
    6.  
    7. const char tA[4] = {'á','â','ã','à '};
    8. for (int j = 0; j < (int)sizeof(tA); j++) str.replace(tA[j],"a");
    To copy to clipboard, switch view to plain text mode 

    Does anyone know what command I have to use or add?

    Thanks!

  2. #2
    Join Date
    Sep 2010
    Location
    Poland
    Posts
    112
    Thanks
    8
    Thanked 3 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Maemo/MeeGo

    Default Re: Accented Character

    I've done something like this recently, but I'd used the map (you are using an array, for me map was just convenient) where I'd put the keys as the strings (these were polish native letters) and values like in your case - simple English chars (the chars as values in the map as well)

    the key in this issue was holding the keys (diacritics) as QString not char, if it was char my method was
    unable to recognize diacritic and replace it

    in that way it worked, my method successfully recognizes diacritics and replace them using appropriate value
    My schedule makes my cry
    My works makes my laugh
    My life makes... oh...no....

  3. #3
    Join Date
    Mar 2006
    Location
    Mexico City
    Posts
    31
    Thanks
    3
    Thanked 1 Time in 1 Post
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Accented Character

    Trader:

    Remember that your source code must be written using ISO-8859, or your code won't work. You have to compare characters written in the same code. Another way, is to convert every thing to the same character code. See QString in your docs.

  4. #4
    Join Date
    May 2010
    Posts
    21
    Thanks
    4
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Accented Character

    Thanks for the help. I solved using the ASCII code.

    Qt Code:
    1. //UTF-8 ASCII Table
    2. const char tA[4] = {225,226,227,228}; //á,â,ã,Ã
    3. const char tE[2] = {233,234}; //é,ê
    4. const char tI[1] = {237}; //Ã*
    5. const char tO[3] = {243,244,245}; //ó,ô,õ
    6. const char tU[2] = {250,252}; //ú,ü
    7. const char tC[1] = {231}; //ç
    To copy to clipboard, switch view to plain text mode 

    Qt Code:
    1. for (unsigned int j = 0; j < sizeof(tA); j++) str.replace(tA[j],"a");
    2. for (unsigned int j = 0; j < sizeof(tE); j++) str.replace(tE[j],"e");
    3. for (unsigned int j = 0; j < sizeof(tI); j++) str.replace(tI[j],"i");
    4. for (unsigned int j = 0; j < sizeof(tO); j++) str.replace(tO[j],"o");
    5. for (unsigned int j = 0; j < sizeof(tU); j++) str.replace(tU[j],"u");
    6. for (unsigned int j = 0; j < sizeof(tC); j++) str.replace(tC[j],"c");
    To copy to clipboard, switch view to plain text mode 

Similar Threads

  1. QregExp: matching accented letters
    By bred in forum Qt Programming
    Replies: 0
    Last Post: 4th January 2011, 10:48
  2. ° character
    By Windsoarer in forum Qt Programming
    Replies: 4
    Last Post: 16th June 2009, 08:51
  3. Character by Character (Unicode?) File Reading
    By mclark in forum Qt Programming
    Replies: 4
    Last Post: 22nd April 2009, 15:28
  4. Problem with accented characters
    By gt.beta2 in forum Qt Programming
    Replies: 2
    Last Post: 14th April 2009, 21:20
  5. How to read QStringList character by character
    By iamjayanth in forum Qt Programming
    Replies: 4
    Last Post: 3rd April 2009, 11:25

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
  •  
Qt is a trademark of The Qt Company.