PDA

View Full Version : Cyrillic support



tehman
7th February 2012, 12:17
Hey there

I am creating a Qt application. This program must support cyrillic fonts (or encoding). So it must take cyrillic data from a database and display that on widgets. What should be added to the program to be sure that cyrillic characters will be displayed correctly on any computer (on any systems where the main language may be not with cyrillic letters)? I was advised to add a cyrillic code page to my project but I have no clue how to do it.

wysota
7th February 2012, 12:27
The only thing you need to do is to make sure you use a font that contains appropriate glyphs. Most standard fonts do. Then just make sure you convert the data from the database into text using the same encoding the data was coded with while being stored in the database (UTF-8 seems the most reasonable choice).

tehman
7th February 2012, 13:15
Added after 5 minutes:

Thank you but I still have the problem. The explaination is as follows.

I have a string and I have to write it to my database:

QString aField; // e.g. there is a text "абвгд"
I use QSqlQuery:

query.bindValue(":aField", aField.toUtf8());
Then in another C++ file I try to get this string from the database with QByteArray:

QByteArray aField_ = q.value(0).toByteArray();
Then I make a codec:

QTextCodec* aCodec = QTextCodec::codecForName("UTF-8");
Here I convert QByteArray to QString:

QString aField = aCodec->toUnicode(aField_);
Now I put the string to the cell of QTableWidget:

item = new QTableWidgetItem(aField);
ui.tableWidget->setItem(rowNumber, 1, item);

Latin characters are displayed okay but cyrrilic are like strange symbols.

What I did wrong?