Results 1 to 10 of 10

Thread: Write Qt program to a language with special symbols

  1. #1
    Join Date
    Jul 2010
    Location
    /home/hakermania/
    Posts
    233
    Thanks
    129
    Thanked 3 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Question Write Qt program to a language with special symbols

    I though that this count be done with the use of tr() but I was wrong...
    I am trying to place this text to a button:
    Déplacer à l'image &suivante
    In french it means "Move to Next image". I place this text into the button with this way:
    ui->nextButton->setText(tr("Déplacer à l'image &suivante"));
    The Qt Creator, after compiling, show the button's text like this:

    As you can see the special character is shown wrong. Is any Qt can recognise these special characters?

  2. #2
    Join Date
    Jan 2009
    Location
    New Zealand
    Posts
    29
    Thanks
    3
    Thanked 1 Time in 1 Post
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Windows

    Default Re: Write Qt program to a language with special symbols

    I agree, this is odd behaviour ...

    My suggestions would be to check the encoding of your source file - if it's ASCII the special characters might be conflicting with Qt's Unicode text system - make sure it's some variant of Unicode. That or look up the Unicode codes of é and à and use backslashes to put them in ...

    If that doesn't work you might need to have a look at QTextCodec::setCodecForTr(). I'm not sure what codecs are available but there should be one which supports French letters.

    I'm not 100% certain about this but hopefully one of the methods above will work.

  3. #3
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: Write Qt program to a language with special symbols

    Salut hakermania,

    if you don't want to change the whole codec you can use QObject::trUtf8(). But you have to make sure, your file is encoded with UTF-8 too.

    Lykurg

  4. #4
    Join Date
    Jul 2010
    Location
    /home/hakermania/
    Posts
    233
    Thanks
    129
    Thanked 3 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Write Qt program to a language with special symbols

    Thanks for your suggestions. Lykurg, I used your suggestion and I finally found a solution!
    I had to use button->setText(QString::fromUtf8("String here"));
    and where there were special characters (like à ) I had to replace them with utf8 special from (e.g. é is written \u00e9)
    There are several webpages where you can find these tables that specify the special characters for every special character.
    So the action from this
    Qt Code:
    1. ui->nextButton->setText(tr("Déplacer à l'image &suivante"));
    To copy to clipboard, switch view to plain text mode 
    should be done
    Qt Code:
    1. ui->nextButton->setText(QString::fromUtf8("D\u00e9placer \u00e0 l'image &suivante"));
    To copy to clipboard, switch view to plain text mode 

  5. #5
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: Write Qt program to a language with special symbols

    Try to use your special letters direct. You just have to make sure that your *.cpp file is encoded in utf8. So you will save time for escaping them.
    Qt Code:
    1. ui->nextButton->setText(trUtf8("Déplacer à l'image &suivante"));
    To copy to clipboard, switch view to plain text mode 

  6. #6
    Join Date
    Aug 2010
    Posts
    107
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Talking Re: Write Qt program to a language with special symbols

    Nice info, thak you all for this post

  7. #7
    Join Date
    Jul 2010
    Location
    /home/hakermania/
    Posts
    233
    Thanks
    129
    Thanked 3 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Write Qt program to a language with special symbols

    No, i've tried this. I need to place these strange symbols....
    When you 're trying to help somebody in the newbie section, don't forget that he is a newbie. Be specific and give examples.

  8. #8
    Join Date
    Jun 2010
    Posts
    142
    Thanks
    11
    Thanked 4 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Write Qt program to a language with special symbols

    Aren't the contents of tr() supposed to be English?

  9. #9
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: Write Qt program to a language with special symbols

    Try the attached project without changing the file encoding and see if it works.
    test_trutf8.zip

  10. #10
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: Write Qt program to a language with special symbols

    Quote Originally Posted by MTK358 View Post
    Aren't the contents of tr() supposed to be English?
    No, you can also perfectly write latin in tr(). The language just should fit in ASCII in normal case.

Similar Threads

  1. Replies: 7
    Last Post: 13th September 2011, 13:15
  2. /usr/bin/ld: Undefined symbols:
    By ataffard in forum Qt Programming
    Replies: 0
    Last Post: 2nd May 2008, 01:24
  3. math symbols
    By genick bar-meir in forum Qt Programming
    Replies: 3
    Last Post: 17th August 2007, 07:29
  4. greek symbols
    By genick bar-meir in forum Qt Programming
    Replies: 2
    Last Post: 17th July 2007, 22:44
  5. Display special symbols
    By ShaChris23 in forum Newbie
    Replies: 1
    Last Post: 30th April 2007, 23:51

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.