Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. How to display chinese in qt-every-opernsource-src-4.8.4
Forum Updated to NodeBB v4.3 + New Features

How to display chinese in qt-every-opernsource-src-4.8.4

Scheduled Pinned Locked Moved General and Desktop
16 Posts 2 Posters 6.3k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • G Offline
    G Offline
    gnoloaixuw
    wrote on last edited by
    #1

    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.

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi and welcome to devnet,

      Just to be sure, why don't you use the Qt installed on your system ?

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      0
      • G Offline
        G Offline
        gnoloaixuw
        wrote on last edited by
        #3

        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

        1 Reply Last reply
        0
        • SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on last edited by
          #4

          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 ?

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

          1 Reply Last reply
          0
          • G Offline
            G Offline
            gnoloaixuw
            wrote on last edited by
            #5
            1. I have installed a Qt 5.1 on your machine and it works completely.

            2. 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

            3. 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.

            1 Reply Last reply
            0
            • SGaistS Offline
              SGaistS Offline
              SGaist
              Lifetime Qt Champion
              wrote on last edited by
              #6

              Could you share the code you use to set the window title and the label text ?

              Interested in AI ? www.idiap.ch
              Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

              1 Reply Last reply
              0
              • G Offline
                G Offline
                gnoloaixuw
                wrote on last edited by
                #7

                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&#40;&#41;;
                

                }

                1 Reply Last reply
                0
                • SGaistS Offline
                  SGaistS Offline
                  SGaist
                  Lifetime Qt Champion
                  wrote on last edited by
                  #8

                  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

                  Interested in AI ? www.idiap.ch
                  Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                  1 Reply Last reply
                  0
                  • G Offline
                    G Offline
                    gnoloaixuw
                    wrote on last edited by
                    #9

                    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.

                    1 Reply Last reply
                    0
                    • G Offline
                      G Offline
                      gnoloaixuw
                      wrote on last edited by
                      #10

                      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();

                      }

                      }

                      1 Reply Last reply
                      0
                      • SGaistS Offline
                        SGaistS Offline
                        SGaist
                        Lifetime Qt Champion
                        wrote on last edited by
                        #11

                        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.

                        Interested in AI ? www.idiap.ch
                        Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                        1 Reply Last reply
                        0
                        • G Offline
                          G Offline
                          gnoloaixuw
                          wrote on last edited by
                          #12

                          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.

                          1 Reply Last reply
                          0
                          • SGaistS Offline
                            SGaistS Offline
                            SGaist
                            Lifetime Qt Champion
                            wrote on last edited by
                            #13

                            What are your configure options when building Qt ?

                            What is displayed in your label ?

                            Interested in AI ? www.idiap.ch
                            Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                            1 Reply Last reply
                            0
                            • G Offline
                              G Offline
                              gnoloaixuw
                              wrote on last edited by
                              #14

                              I just use ./configure to configure the source . The label shows nothing.

                              If I setText("您好aa"), then the label show aa.

                              1 Reply Last reply
                              0
                              • SGaistS Offline
                                SGaistS Offline
                                SGaist
                                Lifetime Qt Champion
                                wrote on last edited by
                                #15

                                Check the output log to see if you have fontconfig/freetype that are found

                                Interested in AI ? www.idiap.ch
                                Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                                1 Reply Last reply
                                0
                                • G Offline
                                  G Offline
                                  gnoloaixuw
                                  wrote on last edited by
                                  #16

                                  ok I get it . Thank you very much !!!

                                  1 Reply Last reply
                                  0

                                  • Login

                                  • Login or register to search.
                                  • First post
                                    Last post
                                  0
                                  • Categories
                                  • Recent
                                  • Tags
                                  • Popular
                                  • Users
                                  • Groups
                                  • Search
                                  • Get Qt Extensions
                                  • Unsolved