Results 1 to 5 of 5

Thread: Encoding problem

  1. #1
    Join Date
    Jun 2012
    Posts
    13
    Thanks
    3
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Encoding problem

    Hello,
    I use the following software: Qt 4.8.1, VC++ 2010, MS Windows, Qt Creator




    I prepared the following QWizardPage class:
    Qt Code:
    1. class AppWizard : public QWizard
    2. {
    3. Q_OBJECT
    4. public:
    5. explicit AppWizard(QWidget *parent = 0);
    6. };
    7.  
    8.  
    9. class WelcomePage : public QWizardPage
    10. {
    11. Q_OBJECT
    12. public:
    13. explicit WelcomePage(QWidget *parent = 0);
    14. private:
    15. QLabel *intro_label_1;
    16. QLabel *intro_label_2;
    17. QVBoxLayout *vbox_layout;
    18. QGridLayout *grid_layout;
    19. QLabel *email_label;
    20. QLineEdit *email_edit;
    21. QRegExpValidator *email_validator;
    22. QLabel *password_label;
    23. QLineEdit *password_edit;
    24. QPushButton *login;
    25. QLabel *register_label;
    26. };
    To copy to clipboard, switch view to plain text mode 

    Qt Code:
    1. WelcomePage::WelcomePage(QWidget *parent) :
    2. QWizardPage(parent)
    3. {
    4. // QTextCodec::setCodecForCStrings(QTextCodec::codecForName("UTF-8"));
    5. setTitle("There is title");
    6. setButtonText(QWizard::NextButton, "Another name");
    7. setButtonText(QWizard::CancelButton, "Another cancel");
    8.  
    9. intro_label_1 = new QLabel("Welcome to software");
    10. intro_label_2 = new QLabel("ółćłćłźźłżżźćźżłźżć.");
    11. email_label = new QLabel("ółłłąął");
    12. email_edit = new QLineEdit(this);
    13.  
    14. password_label = new QLabel("ddsdfdsffds");
    15. password_edit = new QLineEdit(this);
    16. password_edit->setEchoMode(QLineEdit::Password);
    17. login = new QPushButton();
    18. login->setText("dsfsfsfsfdsf");
    19. login->setMaximumWidth(100);
    20. register_label = new QLabel("dsfdfsdsfdsff");
    21.  
    22. grid_layout = new QGridLayout(this);
    23. grid_layout->addWidget(intro_label_1, 0, 0);
    24. grid_layout->addWidget(intro_label_2, 1,0);
    25. grid_layout->addWidget(email_label, 2, 0);
    26. grid_layout->addWidget(email_edit, 2, 1);
    27. grid_layout->addWidget(password_label, 3, 0);
    28. grid_layout->addWidget(password_edit, 3, 1);
    29. grid_layout->addWidget(login, 4, 0);
    30. grid_layout->addWidget(register_label, 7, 0);
    31. }
    To copy to clipboard, switch view to plain text mode 

    However,the encodings fails. I tried to fix this using:
    Qt Code:
    1. // QTextCodec::setCodecForCStrings(QTextCodec::codecForName("UTF-8"));
    To copy to clipboard, switch view to plain text mode 

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

    Thank you for you attention,

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Encoding problem

    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  3. #3
    Join Date
    Jun 2012
    Posts
    13
    Thanks
    3
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Encoding problem

    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?

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Encoding problem

    Quote Originally Posted by newb_developer View Post
    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.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  5. The following user says thank you to wysota for this useful post:

    newb_developer (4th July 2012)

  6. #5
    Join Date
    Jun 2012
    Posts
    13
    Thanks
    3
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Encoding problem

    I'll try to use translate file and it seems to be encoding error. Thank you.
    Last edited by newb_developer; 4th July 2012 at 19:10.

Similar Threads

  1. problem in character encoding
    By fulbay in forum Qt Programming
    Replies: 4
    Last Post: 17th August 2011, 13:29
  2. encoding problem
    By lexqqq in forum Qt Programming
    Replies: 1
    Last Post: 26th November 2010, 23:41
  3. SQLite encoding problem
    By cevou in forum Qt Programming
    Replies: 3
    Last Post: 27th September 2009, 21:37
  4. Encoding problem with QTextEdit
    By alexandernst in forum Newbie
    Replies: 3
    Last Post: 2nd September 2009, 11:49
  5. qt and mysql encoding problem
    By ferasodh in forum Qt Programming
    Replies: 1
    Last Post: 8th September 2007, 09:48

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.