在QT中应用中文

#include <QtGui/QApplication>
#include <QtGui/QPushButton>
#include <QTextCodec>

QString toUnicode(const char *str)
{
 static QTextCodec* GlobalCodec = QTextCodec::codecForName("GBK" );
    return GlobalCodec->toUnicode(str, strlen(str));
}

int main(int argc, char *argv[])
{
 QApplication a(argc, argv);
 //QPushButton *button(QPushButton::tr(toUnicode("我们 World")),&a);
 QPushButton *button=new QPushButton(toUnicode("退出"));
 QObject::connect(button,SIGNAL(clicked()),&a,SLOT(quit()));
 button->show();
    return a.exec();
}

你可能感兴趣的:(qt)