5

I'm trying to display different language strings in my qt app by inserting each language into a QMap<QString, QString> so it can be re-used in several places and put into different combo Boxes across the application. I do this by creating the QMap like so in the CTOR:

m_langMap.insert(QString::fromWCharArray(L"English"), "english");
m_langMap.insert(QString::fromWCharArray(L"Dansk"), "dansk");
m_langMap.insert(QString::fromWCharArray(L"Nederlands"), "dutch");
m_langMap.insert(QString::fromWCharArray(L"Čeština"), "czeck");
m_langMap.insert(QString::fromWCharArray(L"Slovenský"), "slovak");
m_langMap.insert(QString::fromWCharArray(L"Magyar"), "hungarian");
m_langMap.insert(QString::fromWCharArray(L"Român"), "romanian");
m_langMap.insert(QString::fromWCharArray(L"Latviešu"), "latvian");
m_langMap.insert(QString::fromWCharArray(L"Lietuvių"), "lithuanian");
m_langMap.insert(QString::fromWCharArray(L"Polski"), "polish");
m_langMap.insert(QString::fromWCharArray(L"Português"), "portuguese");
m_langMap.insert(QString::fromWCharArray(L"Español"), "spanish");
m_langMap.insert(QString::fromWCharArray(L"Français"), "french");
m_langMap.insert(QString::fromWCharArray(L"Italiano"), "italian");
m_langMap.insert(QString::fromWCharArray(L"Svenska"), "swedish");
m_langMap.insert(QString::fromWCharArray(L"Русский"), "russian");
m_langMap.insert(QString::fromWCharArray(L"Українська"), "ukranian");
m_langMap.insert(QString::fromWCharArray(L"Русский"), "russian");
m_langMap.insert(QString::fromWCharArray(L"中文"), "chinese");
m_langMap.insert(QString::fromWCharArray(L"日本語"), "japanese");

I then insert them into the combo box:

QMap<QString, QString>::const_iterator it = m_langMap.begin();
while (it != m_langMap.end())
{
    ui->comboBox->addItem(it.key());
    ++it;
}

When the app runs, I see the following:

enter image description here

However, if I create a separate .ui file and insert the map the same way, I see the following (even if I include this separate Dialog class into the same application), so clearly there is no font issue as far as the App not knowing how to render the different character sets....yet I cant figure out why the first one won't render the character sets?

Can someone tell me why the first doesn't work but the second does? I checked the Designer and its Locale is set to 'C, Default' in both ui files I've shown below. I can't seem to figure out what else is causing the difference for the first not to work, and the second does work within the same application.

Thanks for any help!

The other test Dialog:

enter image description here

eddie
  • 1,252
  • 3
  • 15
  • 20
Tim
  • 647
  • 1
  • 10
  • 21

2 Answers2

1

Your code is correct, but the problem is that your source file cannot contain Unicode characters - apparently it is using different coding.

Save file as UTF-8 and everything should work!

enter image description here

Nemanja Boric
  • 21,627
  • 6
  • 67
  • 91
  • I believe all the files are saved as UTF-8 right now (although is there a way to check each file and how its saved already?) in Qt Creator->Tools>Text Editor the file encodings is set to UTF-8 right now. The files came from svn from an existing project, so I am not sure how they were saved originally. How can I convert them to UTF-8 via the command line (Unix)? – Tim Feb 08 '13 at 17:39
  • This is supposed to work, however its not working on Ubuntu 12.04 apparently - file -i warning_accept_dialog.cpp warning_accept_dialog.cpp: text/x-c; charset=us-ascii 325 ubu /home/tim/work/src/GUI convmv --notest -fus-ascii -tutf8 warning_accept_dialog.cpp Your Perl version has fleas #37757 #49830 Ready! 326 ubu /home/tim/work/src/GUI file -i warning_accept_dialog.cpp warning_accept_dialog.cpp: text/x-c; charset=us-ascii didnt seem to change. Ive tried several combos and still the same result. – Tim Feb 08 '13 at 18:18
  • 1
    In QtCreator I tried Edit->Selected Encoding->Save File. Still didnt show up as utf8. I found I had to add new file, copy/paste my entire file...and the new file was saved under utf8 encoding and it finally worked! – Tim Feb 08 '13 at 19:05
  • @Tim Glad I could get you some hints to go :) – Nemanja Boric Feb 08 '13 at 19:18
0

In the first screenshot the font used by the combobox is much larger than in the second screenshot. My guess is that you have changed the font either in the GUI designer or in the code and the second (working) screenshot is using the default font. It might be that when you have changed the font size, you have also changed the font to something that doesn't contain all the required Unicode characters. Try changing the font used by the combobox to something else.