PDA

View Full Version : Encoding problem



newb_developer
4th July 2012, 00:10
Hello,
I use the following software: Qt 4.8.1, VC++ 2010, MS Windows, Qt Creator




I prepared the following QWizardPage class:


class AppWizard : public QWizard
{
Q_OBJECT
public:
explicit AppWizard(QWidget *parent = 0);
};


class WelcomePage : public QWizardPage
{
Q_OBJECT
public:
explicit WelcomePage(QWidget *parent = 0);
private:
QLabel *intro_label_1;
QLabel *intro_label_2;
QVBoxLayout *vbox_layout;
QGridLayout *grid_layout;
QLabel *email_label;
QLineEdit *email_edit;
QRegExpValidator *email_validator;
QLabel *password_label;
QLineEdit *password_edit;
QPushButton *login;
QLabel *register_label;
};




WelcomePage::WelcomePage(QWidget *parent) :
QWizardPage(parent)
{
// QTextCodec::setCodecForCStrings(QTextCodec::codecF orName("UTF-8"));
setTitle("There is title");
setButtonText(QWizard::NextButton, "Another name");
setButtonText(QWizard::CancelButton, "Another cancel");

intro_label_1 = new QLabel("Welcome to software");
intro_label_2 = new QLabel("ółćłćłźźłżż źćźżłźżć.");
email_label = new QLabel("ółłłąął");
email_edit = new QLineEdit(this);

password_label = new QLabel("ddsdfdsffds");
password_edit = new QLineEdit(this);
password_edit->setEchoMode(QLineEdit::Password);
login = new QPushButton();
login->setText("dsfsfsfsfdsf");
login->setMaximumWidth(100);
register_label = new QLabel("dsfdfsdsfdsff");

grid_layout = new QGridLayout(this);
grid_layout->addWidget(intro_label_1, 0, 0);
grid_layout->addWidget(intro_label_2, 1,0);
grid_layout->addWidget(email_label, 2, 0);
grid_layout->addWidget(email_edit, 2, 1);
grid_layout->addWidget(password_label, 3, 0);
grid_layout->addWidget(password_edit, 3, 1);
grid_layout->addWidget(login, 4, 0);
grid_layout->addWidget(register_label, 7, 0);
}


However,the encodings fails. I tried to fix this using:

// QTextCodec::setCodecForCStrings(QTextCodec::codecF orName("UTF-8"));

Does Qt Creator use UTF-8 as default encoding? Why unicode chars are not displayed correctly in additional class?

Thank you for you attention,

wysota
4th July 2012, 00:51
QString::fromUtf8()

newb_developer
4th July 2012, 16:40
If I use function QString::fromUtf8 I see another characters, but not correct. I see something like question mark. I tried this option before asking. Is is possible that class file added by Qt Creator has diffrent encoding than UTF-8? Where can I check this issue?

wysota
4th July 2012, 17:06
Is is possible that class file added by Qt Creator has diffrent encoding than UTF-8?
Of course. You could be using latin2 or cp1250.


Where can I check this issue?
In editor settings, AFAIR.

Note, that it is always advised to use only ascii characters in your source code for user visible strings and provide translation files that use national glyphs such as polish, russian, chinese, etc.

newb_developer
4th July 2012, 20:03
I'll try to use translate file and it seems to be encoding error. Thank you.