Results 1 to 16 of 16

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

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

    Default unable to have greek characters appear in a text Label

    Hello everyone,
    the title is self explanatory but only up to a point.
    What really happens is:
    when i input some greek text on the 'text' field of my text label then it appears absolutely fine on the label. I note this, so that you know there are times (ie during design) when greek characters appear fine..

    however i have implemented a small virtual alphanumeric keypad (much like the keypads on the mobile phones). I want, with the aid of a button to switch between english and greek. but when running it and i switch to greek characters they do not appear on the label. instead i get ????? (question marks)
    any ideas?
    nass

  2. #2
    Join Date
    Jan 2006
    Location
    Alingsås, Sweden
    Posts
    437
    Thanks
    3
    Thanked 39 Times in 39 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

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

    How do you create the strings of greek characters? You should probably be using some of the fromUtf8 or fromLocal8Bit... or it could be a font issue.

  3. #3
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,364
    Thanks
    3
    Thanked 5,013 Times in 4,791 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

    How do you enter the characters? In code? Did you remember to convert them from your local encoding to Unicode? (for example using QString::fromLocal8Bit())

  4. #4
    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

  5. #5
    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

  6. #6
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,364
    Thanks
    3
    Thanked 5,013 Times in 4,791 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 

  7. #7
    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

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

    Default problem showing greek in .ui.h files in qtDesigner

    Hello everyone..
    i am very confused as to whether i have installed fonts wrongly.. or if there is a limitation in qtDesigner or whatever else it might be:
    here are the facts:

    i run KDE, in slackware 10.2 and from control centre ->regional & accessibility -> keyboard layout, i have added keyboard support for greek (layout), el (keymap).. i have set the layout variant to 'basic'.
    as far as fonts is concerned i copied all of my ntfs (winXP) partition fonts and installed them both in my personal fonts list and in administrator mode (ie system mode).

    in case you are greek and know linux well i note that i do have a little problem that havent managed to solve. it is not in the scope of this email but if you can help me out i would mostly appreciate it. while i can type greek in all applications i can not type vowels with stress (tonos)! how is that even possible? to make things even more confusing i CAN type vowels with stress in mozilla firefox!!!

    then:

    i am programming a greek oriented application.. therefore all of the button texts, label texts etc are to be in greek... so i have filled all the form's object's 'text' fields in qtDesigner with greek characters, as well as done all the setText("/*some text in greek*/") in my .ui.h files.

    the thing is when i type greek in qtDesigner i see greek on the screen so that is fine...
    However, if i close and reopen qtDesigner and look through the .ui.h file wherever there were greek characters they have been replaced with "???????" (no quotes and the questionmarks are in number identical to the number of greek chars that were there before)

    note that greek text in buttons on the form is still shown fine... only the .ui.h have problems...

    any ideas where i should start looking?
    thank you for your help
    nass

  9. #9
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 975 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

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

    Please, don't start more than one thread on the same problem.

    What encoding does your system use?

  10. #10
    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

    by encoding you mean the locale?
    the value of the LC_* variables?
    its en_US

    i started a new topic because i figured that the previous is a subproblem of this topic.. as in if i solve this the previous with automatically work..

  11. #11
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 975 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

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

    Quote Originally Posted by nass
    by encoding you mean the locale?
    No, I mean the encoding. Like UTF-8, ISO-8859-2 and similar.

  12. #12
    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

    how do i get this info?

  13. #13
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 975 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

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

    The safest way is to see what Qt thinks:
    Qt Code:
    1. #include "qapplication.h"
    2. #include "qtextcodec.h"
    3.  
    4. int main( int argc, char **argv )
    5. {
    6. QApplication app( argc, argv );
    7.  
    8. qDebug( QTextCodec::codecForLocale()->name() );
    9.  
    10. return 0;
    11. }
    To copy to clipboard, switch view to plain text mode 

  14. #14
    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

    says here UTF-8...
    but is that directly taken from the Os or KDe or smth?
    cause a while ago i was trying to make my linux recognise UTF-8 using the info on this link
    http://hektor.umcs.lublin.pl/~mikosm...x-unicode.html
    so i started by

    Qt Code:
    1. "export LC_ALL=en_US.UTF-8"
    To copy to clipboard, switch view to plain text mode 

    and then it says

    Applications started afterwards from the same terminal window should be aware of UTF-8. To check if that's the case, you could for example use the command wc. wc -c will tell you the number of bytes and wc -m the number of characters in a file or in data read from standard input (end typing with Enter and Ctrl-D). In a UTF-8 locale, if text contains non-ASCII characters, the number of bytes will be greater than the number of characters. For example:

    user@host:~$ wc -c
    Bär
    5
    user@host:~$ wc -m
    Bär
    4
    and when i do that test using a greek alpha as opposed to the a with umlaut that is used in the example, i always get 4 as a result.. not 5.. so i am not sure UTF-8 is there as
    running
    Qt Code:
    1. locale
    To copy to clipboard, switch view to plain text mode 
    in a console at my pc states:

    Qt Code:
    1. LANG=
    2. LC_CTYPE="en_US.UTF-8"
    3. LC_NUMERIC="en_US.UTF-8"
    4. LC_TIME="en_US.UTF-8"
    5. LC_COLLATE="en_US.UTF-8"
    6. LC_MONETARY="en_US.UTF-8"
    7. LC_MESSAGES="en_US.UTF-8"
    8. LC_PAPER="en_US.UTF-8"
    9. LC_NAME="en_US.UTF-8"
    10. LC_ADDRESS="en_US.UTF-8"
    11. LC_TELEPHONE="en_US.UTF-8"
    12. LC_MEASUREMENT="en_US.UTF-8"
    13. LC_IDENTIFICATION="en_US.UTF-8"
    14. LC_ALL=en_US.UTF-8
    To copy to clipboard, switch view to plain text mode 
    Last edited by nass; 31st August 2006 at 16:17.

  15. #15
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 975 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

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

    Quote Originally Posted by nass
    says here UTF-8...
    OK, what encoding do you use for string literals in your sources?

  16. #16
    Join Date
    Jan 2020
    Posts
    1
    Qt products
    Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android

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

    I had similar problem but not with Greek chars. I use "material design" font as my buttons icons. since it is a font, it is practically a set of chars. You should find each character code, they are something like 0xFFDD or 0x4C and create a QString like bellow

    QString(L'\uFFDD') for VS compiler and
    QString("\uFFDD") for mingw.

Similar Threads

  1. Unhandled exception in qatomic
    By NewGuy in forum Qt Programming
    Replies: 14
    Last Post: 23rd July 2013, 10: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
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.