PDA

View Full Version : problem with show Chinese



osmanthus
18th January 2009, 08:47
Hi:
everyone,I have a problem with show Chinese.
Below,It's my code:



#include <QTextCodec>
#include <QMainWindow>
#include <QAction>
#include <QMenu>
#include <QTextCodec>
#include <QMenuBar>
#include <QApplication>


class ChineseWindow : public QMainWindow
{

public:
ChineseWindow( QWidget* parent=0 );
virtual ~ChineseWindow();

private:
QAction* iOpenFileAct;[/B]
QMenu* iFileMenu;

};



ChineseWindow::ChineseWindow( QWidget* parent ):QMainWindow( parent )
{
iOpenFileAct = new QAction( tr( "打开" ), this );//this action can not show
iFileMenu = new QMenu( tr( "文件" ), this );//this menu can not show
iFileMenu->addAction( iOpenFileAct );

this->menuBar()->addMenu( iFileMenu );

this->setGeometry( 400, 300, 400, 300 );
this->setWindowTitle( tr( "图片浏览器" ) );

//this->setWindowTitle( QString::fromUtf8( "图片浏览器" ) );
}

ChineseWindow::~ChineseWindow()
{

if( iOpenFileAct )
{
delete iOpenFileAct;
iOpenFileAct = NULL;
}

if( iFileMenu )
{
delete iFileMenu;
iFileMenu = NULL;
}

}


int main( int argc, char** argv )
{

QTextCodec::setCodecForLocale( QTextCodec::codecForName( "UTF-8" ) );
QTextCodec::setCodecForCStrings( QTextCodec::codecForName("UTF-8") );
QTextCodec::setCodecForTr( QTextCodec::codecForName("UTF-8") );


QApplication app( argc, argv );



ChineseWindow cw;
cw.show();

return app.exec();

}


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!

calmspeaker
20th January 2009, 02:49
QTextCodec::setCodecForTr( QTextCodec::codecForName("gbk") );
QTextCodec::setCodecForCStrings( QTextCodec::codecForName("gbk") );
QTextCodec::setCodecForLocale( QTextCodec::codecForName("gbk") );
try this, it works well in my program.