Results 1 to 2 of 2

Thread: problem with show Chinese

  1. #1
    Join Date
    Jan 2009
    Posts
    3
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Talking problem with show Chinese

    Hi:
    everyone,I have a problem with show Chinese.
    Below,It's my code:


    Qt Code:
    1. #include <QTextCodec>
    2. #include <QMainWindow>
    3. #include <QAction>
    4. #include <QMenu>
    5. #include <QTextCodec>
    6. #include <QMenuBar>
    7. #include <QApplication>
    8.  
    9.  
    10. class ChineseWindow : public QMainWindow
    11. {
    12.  
    13. public:
    14. ChineseWindow( QWidget* parent=0 );
    15. virtual ~ChineseWindow();
    16.  
    17. private:
    18. QAction* iOpenFileAct;[/B]
    19. QMenu* iFileMenu;
    20.  
    21. };
    22.  
    23.  
    24.  
    25. ChineseWindow::ChineseWindow( QWidget* parent ):QMainWindow( parent )
    26. {
    27. iOpenFileAct = new QAction( tr( "打开" ), this );//this action can not show
    28. iFileMenu = new QMenu( tr( "文件" ), this );//this menu can not show
    29. iFileMenu->addAction( iOpenFileAct );
    30.  
    31. this->menuBar()->addMenu( iFileMenu );
    32.  
    33. this->setGeometry( 400, 300, 400, 300 );
    34. this->setWindowTitle( tr( "图片浏览器" ) );
    35.  
    36. //this->setWindowTitle( QString::fromUtf8( "图片浏览器" ) );
    37. }
    38.  
    39. ChineseWindow::~ChineseWindow()
    40. {
    41.  
    42. if( iOpenFileAct )
    43. {
    44. delete iOpenFileAct;
    45. iOpenFileAct = NULL;
    46. }
    47.  
    48. if( iFileMenu )
    49. {
    50. delete iFileMenu;
    51. iFileMenu = NULL;
    52. }
    53.  
    54. }
    55.  
    56.  
    57. int main( int argc, char** argv )
    58. {
    59.  
    60. QTextCodec::setCodecForLocale( QTextCodec::codecForName( "UTF-8" ) );
    61. QTextCodec::setCodecForCStrings( QTextCodec::codecForName("UTF-8") );
    62. QTextCodec::setCodecForTr( QTextCodec::codecForName("UTF-8") );
    63.  
    64.  
    65. QApplication app( argc, argv );
    66.  
    67.  
    68.  
    69. ChineseWindow cw;
    70. cw.show();
    71.  
    72. return app.exec();
    73.  
    74. }
    To copy to clipboard, switch view to plain text mode 

    the action and menu can not show,but the window tiltle can show the Chinese.
    why?
    Please give me a hand.Thank you very much!
    Last edited by jpn; 18th January 2009 at 17:42. Reason: missing [code] tags

  2. #2
    Join Date
    Aug 2008
    Location
    Nanjing, China
    Posts
    66
    Thanks
    12
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: problem with show Chinese

    QTextCodec::setCodecForTr( QTextCodec::codecForName("gbk") );
    QTextCodec::setCodecForCStrings( QTextCodec::codecForName("gbk") );
    QTextCodec::setCodecForLocale( QTextCodec::codecForName("gbk") );
    try this, it works well in my program.
    Jerry

Similar Threads

  1. Weird problem: multithread QT app kills my linux
    By Ishark in forum Qt Programming
    Replies: 2
    Last Post: 8th August 2008, 09:12
  2. Steps in solving a programming problem?
    By triperzonak in forum General Programming
    Replies: 8
    Last Post: 5th August 2008, 08:47
  3. Problem hiding main window on minimize
    By bpetty in forum Newbie
    Replies: 5
    Last Post: 18th September 2007, 17:41
  4. How to show custom widget in TreeView's cell :-/
    By WolfMM in forum Qt Programming
    Replies: 2
    Last Post: 7th July 2007, 11:16
  5. Replies: 16
    Last Post: 7th March 2006, 15:57

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.