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>
{
public:
ChineseWindow
( QWidget* parent
=0 );
virtual ~ChineseWindow();
private:
};
{
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 )
{
ChineseWindow cw;
cw.show();
return app.exec();
}
#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();
}
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!
Bookmarks