Results 1 to 8 of 8

Thread: UNICODE UTF-8 String in QT + Eclipse?????

  1. #1
    Join Date
    Dec 2011
    Posts
    33
    Thanks
    56
    Qt products
    Qt4
    Platforms
    Windows

    Default UNICODE UTF-8 String in QT + Eclipse?????

    I use Eclipse IDE for C/C++ & QT integration plug-in , but I can not write in Unicode font ?
    How to resolve ? Thank every body.
    Example: I write : "Chà o tất cả các bạn!" but It show in program: "Chà o t?t c? các b?n"
    Nguyễn Lưu Vũ - Http://nguyenluuvu.com

  2. #2
    Join Date
    Mar 2011
    Location
    Russia, Lipetsk
    Posts
    17
    Thanked 6 Times in 6 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: UNICODE UTF-8 String in QT + Eclipse?????

    Hello.
    Are You create console application? In IDE displays all right?

  3. The following user says thank you to kunashir for this useful post:

    thaihoangluu (29th December 2011)

  4. #3
    Join Date
    Dec 2011
    Posts
    33
    Thanks
    56
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: UNICODE UTF-8 String in QT + Eclipse?????

    HÃ*c.
    I use QpushBotton,... not display utf - 8
    Nguyễn Lưu Vũ - Http://nguyenluuvu.com

  5. #4
    Join Date
    Mar 2011
    Location
    Russia, Lipetsk
    Posts
    17
    Thanked 6 Times in 6 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: UNICODE UTF-8 String in QT + Eclipse?????

    Ok.
    I have done so:
    1. Check code page in Eclipse, maybe it different from system code page.
    if code page is ok, try to use next:
    Qt Code:
    1. QTextCodec *incodec = QTextCodec::codecForName ("CP1251"); // change "CP1251" to our code page
    2. QTextCodec::setCodecForTr(incodec);
    3.  
    4. //in module with pushbutton
    5.  
    6. QPushButton *button = new QPushButton( tr("Chà o tất cả các bạn!"), this);
    To copy to clipboard, switch view to plain text mode 

  6. The following user says thank you to kunashir for this useful post:

    thaihoangluu (30th December 2011)

  7. #5
    Join Date
    Sep 2009
    Location
    Wroclaw, Poland
    Posts
    1,394
    Thanked 342 Times in 324 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: UNICODE UTF-8 String in QT + Eclipse?????

    You can display your text without changing codec:
    Qt Code:
    1. #include <QApplication>
    2. #include <QLabel>
    3.  
    4. int main(int argc, char **argv) {
    5. QApplication app(argc, argv);
    6. QLabel label(QString::fromWCharArray(L"Chà o tất cả các bạn!"));
    7. label.show();
    8. return app.exec();
    9. }
    To copy to clipboard, switch view to plain text mode 

    Edit:
    this is not really good, because of dynamic translations, but this should work ok:
    Qt Code:
    1. #include <QApplication>
    2. #include <QLabel>
    3.  
    4. int main(int argc, char **argv) {
    5. QApplication app(argc, argv);
    6. QLabel label(Qbject::trUtf8("Chà o tất cả các bạn!"));
    7. label.show();
    8. return app.exec();
    9. }
    To copy to clipboard, switch view to plain text mode 

    edit 2:
    try to call QTextCodec::setCodecForTr(QTextCodec::codecForName ("UTF-8")); in your main() function, then you should be able to use regular tr("") method:
    Qt Code:
    1. #include <QApplication>
    2. #include <QLabel>
    3.  
    4. int main(int argc, char **argv) {
    5. QApplication app(argc, argv);
    6. QTextCodec::setCodecForTr(QTextCodec::codecForName("UTF-8"));
    7. QLabel label(Qbject::tr("Chà o tất cả các bạn!"));
    8. label.show();
    9. return app.exec();
    10. }
    To copy to clipboard, switch view to plain text mode 
    Last edited by stampede; 29th December 2011 at 11:18.

  8. The following user says thank you to stampede for this useful post:

    thaihoangluu (30th December 2011)

  9. #6
    Join Date
    Dec 2011
    Posts
    33
    Thanks
    56
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: UNICODE UTF-8 String in QT + Eclipse?????

    Quote Originally Posted by kunashir View Post
    Ok.
    I have done so:
    1. Check code page in Eclipse, maybe it different from system code page.
    if code page is ok, try to use next:
    Qt Code:
    1. QTextCodec *incodec = QTextCodec::codecForName ("CP1251"); // change "CP1251" to our code page
    2. QTextCodec::setCodecForTr(incodec);
    3.  
    4. //in module with pushbutton
    5.  
    6. QPushButton *button = new QPushButton( tr("Chà o tất cả các bạn!"), this);
    To copy to clipboard, switch view to plain text mode 
    It's code Error

    Quote Originally Posted by stampede View Post
    You can display your text without changing codec:
    Qt Code:
    1. #include <QApplication>
    2. #include <QLabel>
    3.  
    4. int main(int argc, char **argv) {
    5. QApplication app(argc, argv);
    6. QLabel label(QString::fromWCharArray(L"Chà o tất cả các bạn!"));
    7. label.show();
    8. return app.exec();
    9. }
    To copy to clipboard, switch view to plain text mode 

    Edit:
    this is not really good, because of dynamic translations, but this should work ok:
    Qt Code:
    1. #include <QApplication>
    2. #include <QLabel>
    3.  
    4. int main(int argc, char **argv) {
    5. QApplication app(argc, argv);
    6. QLabel label(Qbject::trUtf8("Chà o tất cả các bạn!"));
    7. label.show();
    8. return app.exec();
    9. }
    To copy to clipboard, switch view to plain text mode 

    edit 2:
    try to call QTextCodec::setCodecForTr(QTextCodec::codecForName ("UTF-8")); in your main() function, then you should be able to use regular tr("") method:
    Qt Code:
    1. #include <QApplication>
    2. #include <QLabel>
    3.  
    4. int main(int argc, char **argv) {
    5. QApplication app(argc, argv);
    6. QTextCodec::setCodecForTr(QTextCodec::codecForName("UTF-8"));
    7. QLabel label(Qbject::tr("Chà o tất cả các bạn!"));
    8. label.show();
    9. return app.exec();
    10. }
    To copy to clipboard, switch view to plain text mode 
    The Fisrt code it's Work, but the second and third : Error
    1.png

    Thank everybody for watching.
    Nguyễn Lưu Vũ - Http://nguyenluuvu.com

  10. #7
    Join Date
    Mar 2011
    Location
    Russia, Lipetsk
    Posts
    17
    Thanked 6 Times in 6 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: UNICODE UTF-8 String in QT + Eclipse?????

    Your have error in code:

    Qt Code:
    1. QLablel lable (Qbject::tr(...));
    2. //rigth path this
    3. QLablel lable (QObject::tr(...));
    To copy to clipboard, switch view to plain text mode 

    You missed "O" in QObject.

  11. The following user says thank you to kunashir for this useful post:

    thaihoangluu (31st December 2011)

  12. #8
    Join Date
    Dec 2011
    Posts
    33
    Thanks
    56
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: UNICODE UTF-8 String in QT + Eclipse?????

    Quote Originally Posted by kunashir View Post
    Your have error in code:

    Qt Code:
    1. QLablel lable (Qbject::tr(...));
    2. //rigth path this
    3. QLablel lable (QObject::tr(...));
    To copy to clipboard, switch view to plain text mode 

    You missed "O" in QObject.
    Oh.Sorry kunashir , I don't see

    THANK EVERYBODY
    My problem is solved.

    Cheers.
    Last edited by thaihoangluu; 31st December 2011 at 01:41.
    Nguyễn Lưu Vũ - Http://nguyenluuvu.com

Similar Threads

  1. Replies: 0
    Last Post: 4th February 2011, 09:02
  2. Replies: 7
    Last Post: 22nd December 2010, 08:13
  3. Unicode
    By qtuser20 in forum Qt Programming
    Replies: 0
    Last Post: 28th September 2009, 21:43
  4. std:string how to change into system:string?
    By yunpeng880 in forum Qt Programming
    Replies: 1
    Last Post: 14th April 2009, 08:51
  5. [MacOSX,eclipse CDT]want eclipse to know Qt classes
    By lolveley in forum Installation and Deployment
    Replies: 7
    Last Post: 27th July 2007, 23:52

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
  •  
Qt is a trademark of The Qt Company.