Results 1 to 16 of 16

Thread: unable to have greek characters appear in a text Label

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Jan 2006
    Location
    Skopje, Macedonia
    Posts
    11
    Thanks
    1
    Thanked 1 Time in 1 Post
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows Maemo/MeeGo

    Default Re: unable to have greek characters appear in a text Label

    You can also set the Text encoding on the application level and then you have to use tr() tags for every string that you are using.
    Check the class QTextCodec
    http://doc.trolltech.com/4.1/qtextcodec.html

    Qt Code:
    1. int main( int argc, char ** argv )
    2. {
    3.  
    4.  
    5. QApplication a( argc, argv );
    6. QTextCodec *utfCodec = QTextCodec::codecForName("UTF-8"); //creating new utf-8 codec
    7. QTextCodec::setCodecForTr(utfCodec); // setting the utf-8 codec for the tr() tags
    8.  
    9. FormMain w; // the main window
    10. w.show();
    11.  
    12. return a.exec();
    13. }
    To copy to clipboard, switch view to plain text mode 
    Before creating the main window create the utf-8 (or the one you need) codec and then set that codec to be used for the tr() tags.

    Then in the files all the strings that should be shown should be passed trough the tr() tag.
    Qt Code:
    1. QMessageBox::critical( 0, tr("КМ Визуелизација") ,
    2. tr("Не можам да ја пронајдам конфигурациската датотека за боите на шемите:\n %1").arg(Path), tr("Во ред"));
    To copy to clipboard, switch view to plain text mode 
    The cirillyc letters are shown good

    GREETZ, chombium

  2. #2
    Join Date
    Jul 2006
    Posts
    79
    Qt products
    Qt3 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: unable to have greek characters appear in a text Label

    i basically use const char *charArray="/*some chars*/;

    for example for the alphanumeric button 2 the corresponding char array is:

    charArray2greek="αβγά2" (= alpha,beta,gama,alpha with stress, two)

    the reason i used const char is so i can declare whole arrays like above but have the ability to point to just one character.. basically a timed counter counts the number of clicks on each button while cycling through each character in the button's corresponding charArray. then when the user stops clicking a character is picked and output on a label. now when i use greek that character is not shown on the screen, instead i get "??????".

    moreover i get the same problem if at runtime i try to set the Text (to smth in greek) of a button. for example on the keypad i also have a button to switch between greek and english.. the text on the button is "Language: English".(in greek with greek characters). now once i press the button the language is switched and the text should also be changed to correspond to "Language: Greek".. well that does not happen.. ie at design time i can input greek characters properly in the text field of a button and of a label but at run time this does not seem to work...

    so i am trying to get this utf8 thing straight...
    i tried using unicode numbers to write the strings "language: English" and Language: Greek"
    it looks basically like: languageButton->setText(tr("\0393\03BB\03CE\03C3\03C3\03B1\003A\0 00D\0395\03BB\03BB\03B7\03BD\03B9\03BA\03AC"));

    i thought that wouldmight work.... but then again it does not.. i get the code itself appear on the button.
    should i perhaps use smth else instead of tr? shouldi write in unicode or use simple greek characters directly input from the keyboard?

    thank you all for your help
    nass

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

    Default Re: unable to have greek characters appear in a text Label

    Just use QString::fromLocal8Bit() when setting the characters.
    Qt Code:
    1. greekEdit->setText(QString::fromLocal8Bit(charArray2greek[1]));
    To copy to clipboard, switch view to plain text mode 

  4. #4
    Join Date
    Jul 2006
    Posts
    79
    Qt products
    Qt3 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: unable to have greek characters appear in a text Label

    this is interesting: i just realised this is happening.
    i took this directly from within the designer window.. it appears that if i close the designer and restart it the greek characters don't even appear in the .ui.h file!
    i asure you when i type the characters they appear fine... but for some unknown reason when i restarted the pc just now everything that i have typed in greek appears like ??? (exception to this is the text on the buttons which when i open a project in the designer it appears fine)

    charGRArray2a="????2";
    charGRArray2A="???2";
    charGRArray3a="????3?";
    charGRArray3A="???3?";
    charGRArray4a="?????4";
    charGRArray4A="???4";
    charGRArray5a="???5";
    charGRArray5A="???5";
    charGRArray6a="????6";
    charGRArray6A="???6";
    charGRArray7a="????7$";
    charGRArray7A="???7$";
    charGRArray8a="????8";
    charGRArray8A="???8";
    charGRArray9a="????9";
    charGRArray9A="???9";

    just to make sure:
    i have copied all the fonts i found in my ntfs (winXP) partition and installed them both in administrator mode and in personal mode... i mean i think and i hope and i believe i have adequate number of fonts...! or don't i?
    nass

Similar Threads

  1. Unhandled exception in qatomic
    By NewGuy in forum Qt Programming
    Replies: 14
    Last Post: 23rd July 2013, 09:49

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.