LinuxSir.cn,穿越时空的Linuxsir!

 找回密码
 注册
搜索
热搜: shell linux mysql
查看: 2603|回复: 4

给Qt教程一加点汉字“为人民服务”。怎么显不出来呢?

[复制链接]
发表于 2003-6-9 15:37:11 | 显示全部楼层 |阅读模式
/****************************************************************
**
** Qt教程一 - 2
**
****************************************************************/

#include <qapplication.h>
#include <qpushbutton.h>


int main( int argc, char **argv )
{
    QApplication a( argc, argv );

    QPushButton hello( "Hello world!\n为人民服务!", 0 );
    hello.resize( 100, 30 );

    a.setMainWidget( &hello );
    hello.show();
    return a.exec();
}
以上程序编译没问题,可运行结果却显示得像天书。
特请教高手,先谢过了。在线等待。
发表于 2003-6-9 18:13:29 | 显示全部楼层

hello-&gt;setText(&quot;为人民服务&quot;);

试试吧
发表于 2003-6-9 18:14:21 | 显示全部楼层
规范的方法要去看QT的国际化文档。编程时可以用这种简便的方法处理一下:

  1. #include<qapplication.h>
  2. #include<qlabel.h>
  3. #include<qtextcodec.h>
  4. #include<qobject.h>
  5. #include<qstring.h>

  6. int main( int argc, char **argv )
  7. {
  8.     QApplication a( argc, argv );
  9.     qApp->setDefaultCodec(QTextCodec::codecForName("GBK"));

  10.     QLabel label(QObject::tr("你好!"), NULL);
  11.     a.setMainWidget(&label);
  12.     label.show();
  13.     return a.exec();
  14. }
复制代码
发表于 2003-6-10 08:58:18 | 显示全部楼层
hello( tr("Hello world!\n为人民服务!"), 0 );
然后另外生成ts文件,再用linguist翻译过来。
 楼主| 发表于 2003-6-10 09:07:13 | 显示全部楼层

问题解决,谢谢!

spartutu的方法不行。
kj501的OK!
kancon的有点深度,还弄不明白。
一并谢谢了。
您需要登录后才可以回帖 登录 | 注册

本版积分规则

快速回复 返回顶部 返回列表