PDA

View Full Version : Language Selector QCombobox question



MarkoSan
31st January 2008, 05:39
Good morning to all, especialy nice and kind experts like wysota and jpn!!! :D

Can I get some help, please? I need a QComboBox that act as language selector widget. I've written this (header):
#ifndef CLANGUAGESETTINGSPAGE_H_
#define CLANGUAGESETTINGSPAGE_H_

// qt includes
#include <QtGui>
#include <QVBoxLayout>
#include <QHBoxLayout>
#include <QPointer>
#include <QString>

// custom includes
#include "globals.h"
class CLanguageSettingsPage : public QWidget
{
public:
CLanguageSettingsPage(QWidget* pParent=0);
~CLanguageSettingsPage();

inline QPointer<QLabel> languageSelectorLB()
{ return m_pLangaugeSelectorLB; };
inline QPointer<QComboBox> languageSelectorCB()
{ return m_pLanguageSelectorCB; };
inline QPointer<QHBoxLayout> languageSelectorHBL()
{ return m_pLanguageSelectorHBL; };

private:
QPointer<QLabel> m_pLangaugeSelectorLB; // lang. sel. label
QPointer<QComboBox> m_pLanguageSelectorCB; // lang. sel. combo box
QPointer<QHBoxLayout> m_pLanguageSelectorHBL; // lang. sel. horiz. layout
};

#endif /*CLANGUAGESETTINGSPAGE_H_*/and it's implementation:
#include "CLanguageSettingsPage.h"

CLanguageSettingsPage::CLanguageSettingsPage(QWidg et* pParent)
: QWidget(pParent)
{
// language selector label
m_pLangaugeSelectorLB=new QLabel(tr("Client default language:"), this); // creates new label
Q_CHECK_PTR(m_pLangaugeSelectorLB); // checks creation
//m_pLangaugeSelectorLB->setFrameStyle(QFrame::Panel | QFrame::Raised); // test
// **** end oflanguage selector label

// language selector combo box
m_pLanguageSelectorCB=new QComboBox(this); // creates new combo box
Q_CHECK_PTR(m_pLanguageSelectorCB); // checks creation
m_pLanguageSelectorCB->addItem("SlovenÅ¡čina");
m_pLanguageSelectorCB->addItem("English");
m_pLanguageSelectorCB->addItem("Deutsch");
m_pLanguageSelectorCB->addItem("Italiano");
m_pLanguageSelectorCB->addItem("Español");
// **** end oflanguage selector combo box

// layout creation
m_pLanguageSelectorHBL=new QHBoxLayout(); // creates new layout
Q_CHECK_PTR(m_pLanguageSelectorHBL); // checks creation
// adds widget to layout
m_pLanguageSelectorHBL->addWidget(m_pLangaugeSelectorLB);
// adds widget to layout
m_pLanguageSelectorHBL->addWidget(m_pLanguageSelectorCB);
// sets layout
setLayout(m_pLanguageSelectorHBL);
}

CLanguageSettingsPage::~CLanguageSettingsPage()
{
}Everything works fine, however, language native charaters (in Slovenian language and Espanol) are not shown. How do I achieve so native characters will be shown?? I've attached a sscreenshot of a problem.

ChristianEhrlicher
31st January 2008, 08:15
Your compiler treats the source as whatever it likes (either latin1 or utf-8 I guess) but there your native chars are no available / wrong.
Don't use native chars in source code as you can never predict how (== which encoding) a specific compiler interprets the source.

MarkoSan
31st January 2008, 08:25
So, there is no solution to this problem? Then I simply must translate all languages into English (which is not a problem, but I would really like to know how to implement more than language support for further use).

ChristianEhrlicher
31st January 2008, 08:36
use QTranslator to translate the english names into their native characters

MarkoSan
31st January 2008, 08:55
Ok, will do so, but i do not like this solution, but can I use, QTextCodec class, do you have any experience with it?

ChristianEhrlicher
31st January 2008, 09:03
QTextCodec can't help you here either - As I said you can't be sure what codec the compiler is using.
But this can work:


QString str = "Sloven" + QChar(0x1234) + QChar(0x1235) + "ina";

where 0x1234 and 0x1235 should be the correct unicode numbers for Å¡ and č .