How to display chinese in qt-every-opernsource-src-4.8.4
-
Dear all
I downloaad qt-everywhere-opensource-src-4.8.4.tar.gz from http://download.qt-project.org/archive/qt/4.8/4.8.4/qt-everywhere-opensource-src-4.8.4.tar.gz. I compile and install it in the Ubuntu 13.04. It can't display Chinese character completely. For example, if I show a dialog, I can use the setWindowTitle() function to display chinese character in the title of the dialog, but I can't use the setText() function to display any chinese character in the label on the dialog.
So I think the codecs is right, the problem is about the font. And I find the fonttype files in the /usr/share/fonts/truetype/wqy/ . And I put these two files in the /usr/local/Trolltech/Qt-4.8.4/lib/fonts/ . But it doesn't work.
Please help me to fix this problem.
-
Hi and welcome to devnet,
Just to be sure, why don't you use the Qt installed on your system ?
-
in fact, i have installed a qt in my Ubuntu. I use this http://download.qt-project.org/official_releases/qt/5.1/5.1.0/qt-linux-opensource-5.1.0-x86-offline.run. And it can work. It can display chinese character compelely.
But I need to transplant the qt to arm platform. So i want to test it first on the x86 computer. But it can't display chinese character. I want to find the difference between the install version and the compile version. But I get confused now.
So please help me to fix this problem
-
You are not making yourself very clear.
Lets try to sum up:
- You have installed a Qt 5.1 on your machine and it works.
- You have compiled a Qt 4.8.4 where it does not work.
- You want to run your application on an arm board.
Am I getting you right ?
-
-
I have installed a Qt 5.1 on your machine and it works completely.
-
I have compiled a Qt 4.8.4 and it works. I can use the setWindowTitle to display Chinese character in the title of the dialog. But I can't use the setText to display Chinese character in the label. I guess I miss some font type files such as wenquanyi.ttc which I find in the /usr/share/font/ of the system
-
I want to run it on an arm board. But I have't tried yet. When I finish the step 2 , i will try.
Please help me to solve the chinese character problem.
-
-
Could you share the code you use to set the window title and the label text ?
-
main.cpp as follow
#include "dialog.h"
#include <QApplication>
#include <QLabel>
#include <QTextCodec>int main(int argc, char *argv[])
{
QApplication a(argc, argv);
Dialog w;QLabel *l = new QLabel(&w); l->setText(QObject::trUtf8("您好")); w.setWindowTitle(QObject::trUtf8("您好")); w.show(); return a.exec();
}
-
Please enclose your code with coding tags, that will make it readable.
You don't call show on your label so it won't appear
-
sorry, I just copy it from my file. I don't it will ignore the space.
in fact, it can show. Beacuse QLabel *l = new QLabel(&w); the label is belong to the dialog.
-
I don't know what is code tags. I just try to copy it again.
#include “dialog.h”
#include <QApplication>
#include <QLabel>
#include <QTextCodec>int main(int argc, char *argv[])
{
QApplication a(argc, argv);Dialog w;
QLabel *l = new QLabel(&w);
l->setText(QObject::trUtf8(“您好”));
w.setWindowTitle(QObject::trUtf8(“您好”));
w.show(); return a.exec();
}
}
-
Sorry, I missed that.
For the coding tags, it's the first icon to the right. It's simply a @ at the beginning and another at the end of the code block.
Are you sure that your Dialog doesn't hide the label somehow ? If the title is shown correctly the text in the label should also be.
Since your are building Qt yourself I would recommend using a more recent version.
-
I'm sure the dialog doesn't hide the label. Because I use the same code in the install version and compile version. The install version can show chinese character correctly. But the qt source compiled by myself just can show the chinese character in title correctly, but the text in the label can not show chinese character correctly.
I guess the setWindowTitle is different with setText. I guess the title has just one type of font. But the text has variant font. Is that right. I use the 4.8.4 and 4.8.5 version which are latest. What is the path of the font type file? How should I add the file ? or how to fix this problem.
-
What are your configure options when building Qt ?
What is displayed in your label ?
-
I just use ./configure to configure the source . The label shows nothing.
If I setText("您好aa"), then the label show aa.
-
Check the output log to see if you have fontconfig/freetype that are found
-
ok I get it . Thank you very much !!!