PDA

View Full Version : unable to have greek characters appear in a text Label



nass
30th August 2006, 13:07
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

e8johan
30th August 2006, 14:17
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.

wysota
30th August 2006, 14:17
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())

chombium
30th August 2006, 15:42
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



int main( int argc, char ** argv )
{


QApplication a( argc, argv );
QTextCodec *utfCodec = QTextCodec::codecForName("UTF-8"); //creating new utf-8 codec
QTextCodec::setCodecForTr(utfCodec); // setting the utf-8 codec for the tr() tags

FormMain w; // the main window
w.show();

return a.exec();
}

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.


QMessageBox::critical( 0, tr("КМ Визуелизација") ,
tr("Не можам да ја пронајдам конфигурациската датотека за боите на шемите:\n %1").arg(Path), tr("Во ред"));

The cirillyc letters are shown good ;)

GREETZ, chombium

nass
31st August 2006, 11:34
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\000D\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

wysota
31st August 2006, 11:46
Just use QString::fromLocal8Bit() when setting the characters.

greekEdit->setText(QString::fromLocal8Bit(charArray2greek[1]));

nass
31st August 2006, 12:13
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

nass
31st August 2006, 12:47
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

jacek
31st August 2006, 13:15
Please, don't start more than one thread on the same problem.

What encoding does your system use?

nass
31st August 2006, 13:35
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..

jacek
31st August 2006, 13:39
by encoding you mean the locale?
No, I mean the encoding. Like UTF-8, ISO-8859-2 and similar.

nass
31st August 2006, 15:21
how do i get this info?

jacek
31st August 2006, 15:44
The safest way is to see what Qt thinks:
#include "qapplication.h"
#include "qtextcodec.h"

int main( int argc, char **argv )
{
QApplication app( argc, argv );

qDebug( QTextCodec::codecForLocale()->name() );

return 0;
}

nass
31st August 2006, 16:04
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/~mikosmul/computing/articles/linux-unicode.html
so i started by


"export LC_ALL=en_US.UTF-8"

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
locale in a console at my pc states:


LANG=
LC_CTYPE="en_US.UTF-8"
LC_NUMERIC="en_US.UTF-8"
LC_TIME="en_US.UTF-8"
LC_COLLATE="en_US.UTF-8"
LC_MONETARY="en_US.UTF-8"
LC_MESSAGES="en_US.UTF-8"
LC_PAPER="en_US.UTF-8"
LC_NAME="en_US.UTF-8"
LC_ADDRESS="en_US.UTF-8"
LC_TELEPHONE="en_US.UTF-8"
LC_MEASUREMENT="en_US.UTF-8"
LC_IDENTIFICATION="en_US.UTF-8"
LC_ALL=en_US.UTF-8

jacek
31st August 2006, 16:20
says here UTF-8...
OK, what encoding do you use for string literals in your sources?

MhmRhm
31st January 2020, 19:25
I had similar problem but not with Greek chars. I use "material design (https://cdn.materialdesignicons.com/4.8.95/)" 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.