How to display Chinese

  
after Ubuntu Qt is transplanted to the development board

Qt is an object-oriented framework. It can display Chinese in Ubuntu, but it can not be displayed in Chinese when porting Qt to the development board. How to make Qt open? What is displayed on the board? The following small series will introduce you to the way Ubuntu Qt ported to the development board to display Chinese.

There are two main points for displaying Chinese. One is the encoding, but the font.

There are various arguments about the code online search, utf8 gbk gb2312, I use utf8.

The development board must also have a corresponding Chinese font to display Chinese, I Here in the Ubuntu 12.04 installation directory usr /share /fonts /truetype /wqy directory, copy this to the font library in the development board Qt library, pay attention to the Qt font path to the environment variable QT_QWS_FONTDIR = /opt /qt -4.8.4 /lib /fonts

Finally, the code in the main function to:

#include & ldquo; widget.h & rdquo;

#include QApplication

#include 《QTextCodec》

int main(int argc, char *argv[])

{

QApplication a(argc, Argv);

QTextCodec *codec = QTextCodec::codecForName(“utf8”);

QTextCodec::setCodecForLocale(codec);

QTextCodec::setCodecForCStrings(codec );

QTextCodec::setCodecForTr(codec);

QFont font;

font.setFamily((“wqy-microhei”));

Widget w;

w.setWindowFlags(Qt::FramelessWindowHint);

w.show();

return a.exec();

}

Use a tr macro such as ui-"statelabel-"setText(tr) when using (“The camera is already running!”))

This way, you can use Chinese fonts when running on the development board, and there will be no problems with font size and layout.

The above is the introduction of Linux Qt porting to the development board to display Chinese, mainly because there is no corresponding Chinese font in the development board, just import the Qt font path into the development board.

Copyright © Windows knowledge All Rights Reserved