编写中文软件,使用_Q(x)宏就行了,如果需要编写国际化软件,再使用tr(x)宏。。。
这样的话,在Win98/WinNT中执行时只会进行字符串拷贝,而在Linux执行时会进行一次UTF-32到UTF-16的转换(因为Linux中的wchar_t是UTF-32)。
这样的话,在Win98/WinNT中执行时只会进行字符串拷贝,而在Linux执行时会进行一次UTF-32到UTF-16的转换(因为Linux中的wchar_t是UTF-32)。
Other#include <qapplication>
#include <qfont>
#include <qpushbutton>
#include <qtcore qtextcodec>
#include <string.h>
#define _Q(x) QString::fromWCharArray(L##x)
int main(int argc, char* argv[])
{
QApplication app(argc, argv);
QWidget window;
window.resize(200, 120);
QPushButton quit(_Q("我是中文"), &window);
quit.setFont(QFont("SimSun", 18, QFont::Bold));
quit.setGeometry(10, 40, 180, 40);
QObject::connect(&quit, SIGNAL(clicked()), &app, SLOT(quit()));
window.show();
return app.exec();
}</string.h></qtcore></qpushbutton></qfont></qapplication>
[修改于 9年3个月前 - 2016/05/28 12:47:11]
引用 .........:Qt4一个很坑的地方就是英语中心主义,char字符串就是设计为仅兼容英语Latin1的。。。
我都是用tr或者QString
200字以内,仅用于支线交流,主线讨论请采用回复功能。