PDA

View Full Version : problem with Hebrew font in a control



HeX0R
10th February 2010, 06:54
Hi.
i am trying to made my first application in Qt.
and i got a problem with the Hebrew.
i made a lineEdit control with pushButton and listWidget. when the buttons clickEvent occur the text in the lineEdit goes to the listWidget,
normally, all working perfect.
but if im trying to insert a hardcoded item to the listwidget that writen in Hebrew i will get in the list only "????"...

i am tried to use the:
QTextCodec *codec = QTextCodec::codecForName("iso8859-8");
but hopeless...

any help please??? :)

Lykurg
10th February 2010, 10:22
Hi,

first: How do you save your files? Suppose utf8 then try:
setText(trUtf8("שלום")).
Works for me,

Lykurg

HeX0R
10th February 2010, 11:04
Thank you, but it is not working for me... :rolleyes:
and i am not handle with files yet...

Lykurg
10th February 2010, 11:16
so how are your files are encoded? and please post the relevant code where you insert the hebrew text to the list widget.

HeX0R
10th February 2010, 11:25
it is only my first time i am using the Qt framework.
and i am just tried to do a simple ui with a list and button.
when the user press the button something will add to the list.
in English its absolutely working but in Hebrew its doesn't.

i tried verity of code the last one was:


void MainWindow::on_pushButton_clicked()
{
ui->listWidget->addItem(trUtf8("שלום"));}


edit:
i even tried this code:


QString text = "שלום";
QTextCodec *codec = QTextCodec::codecForName("Windows-1255");
QByteArray encodedString = codec->fromUnicode(text);
ui->textEdit->append(encodedString);


Thank you for helping me! :)

HeX0R
10th February 2010, 12:07
Lykurg, thank you, i did it... :)

thanks the code:


QByteArray encode = "שלום";
QTextCodec* code = QTextCodec::codecForName("Windows-1255");
QString string = code->toUnicode(encode);
ui->textEdit->append(string);

but it is the right way to do this???

Edit:
something goes wrong...
when i done this on my native system its work perfectly...
but when i tried this code my virtual machine i got ???? again....

Edit II:
I have to mention that my goal is to build application for the S60 platform
and in the VM i have the S60 SDK installed... if its change something...

Lykurg
10th February 2010, 13:13
QByteArray encode = "שלום";
QTextCodec* code = QTextCodec::codecForName("Windows-1255");
QString string = code->toUnicode(encode);
ui->textEdit->append(string);

but it is the right way to do this???


If it works it is ok, but it is to much for such a simple thing. Still I can only recomend to use pure utf8 for all. Files and then trUtf8.



Edit:
something goes wrong...
when i done this on my native system its work perfectly...
but when i tried this code my virtual machine i got ???? again....

Edit II:
I have to mention that my goal is to build application for the S60 platform
and in the VM i have the S60 SDK installed... if its change something...

Ahh, the s60! I had trouble with that also. I was trying to set hebrew with vovels. But with the new release I don't have had troubles. So I would suggest. make a simple compilable program which reproduce your error, and I will check it at home with my Xpressmusic and we will see further...

HeX0R
10th February 2010, 17:16
Thank you man...
but i deleted the project and the entire environment and started from scrach...

Now i can read Hebrew that hardcoded and even readen from file...

But i have another problem with this ... ye rigth...
I change the button "Add" to Hebrew and now he gibrish....
you can see in the picture the button in the rigth upper corner...
http://img37.imageshack.us/img37/5615/webcam000001.jpg

Lykurg
10th February 2010, 19:38
Now i can read Hebrew that hardcoded and even readen from file...

יופי! With the button: Did you use designer for creating the GUI? If so, see if it uses utf8 as well. If you don't find the error just upload a running sample code and we'll see.

Lykurg

HeX0R
10th February 2010, 20:06
No i made it with the Creator.
here i uploded all the "project" source:
Link to Download page (http://cid-40f2b6c9b563e00f.skydrive.live.com/self.aspx/.Public/ReadText.rar)

Thank you very much!

Lykurg
10th February 2010, 20:40
Hi,

there is some strangeness inside you code (at least for me...). I still can say: use utf8 since Qt use that codec. Make sure you have configured Qt Creator to use utf8!
Also QTextCodec was not used correct:
void MainReader::on_pushButton_clicked()
{
QFile file(ui->lineEdit->text());
if(file.open(QIODevice::ReadOnly | QIODevice::Text))
{
QTextStream in(&file);
in.setCodec("Windows-1255");
QString line = in.readAll();
ui->textEdit->append(line);
}
}

void MainReader::on_pushButton_2_clicked()
{
ui->textEdit->append(trUtf8("נסיון"));
}

and with the button no problem at all. And as a further suggestion: Have a look at the layout mechanism. QHBoxLayout etc.

HeX0R
11th February 2010, 12:54
1) Thank you very much.
2) How can i configure my Creator to use UTF8?
3) the code you written in Button 2 appended only gibberish...
4) with the button on the right up corner, in Windows their is no problem, but in S60 his text in gibberish..

HeX0R
11th February 2010, 14:27
What is the chance that the UTF8 in Windows and S60 are different??
i declared the name of the button like so:


ui->pushButton_2->setText(QString::fromUtf8("\327\224"));

in Windows i got "ה"
in S60 i got "ש"
What the heck? what i am doing wrong???