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. Why can't it display Chinese?
Forum Updated to NodeBB v4.3 + New Features

Why can't it display Chinese?

Scheduled Pinned Locked Moved Unsolved General and Desktop
13 Posts 3 Posters 1.2k Views
  • 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.
  • Q Offline
    Q Offline
    Qingshui Kong
    wrote on last edited by
    #1

    Hello everyone,
    Could somebody help me?
    I create a QMainWindow. I set 'windowTitle' to some Chinese in the Designer. It works.
    But if I QTextCodec::setCodecForLocale();, it doesn't work.
    Please give me some advice.
    Thank you in advance.

    jsulmJ Q 2 Replies Last reply
    0
    • Q Qingshui Kong

      Hello everyone,
      Could somebody help me?
      I create a QMainWindow. I set 'windowTitle' to some Chinese in the Designer. It works.
      But if I QTextCodec::setCodecForLocale();, it doesn't work.
      Please give me some advice.
      Thank you in advance.

      jsulmJ Offline
      jsulmJ Offline
      jsulm
      Lifetime Qt Champion
      wrote on last edited by
      #2

      @Qingshui-Kong said in Why can't it display Chinese?:

      Please give me some advice

      Please provide more information/show the code...

      https://forum.qt.io/topic/113070/qt-code-of-conduct

      Q 1 Reply Last reply
      0
      • jsulmJ jsulm

        @Qingshui-Kong said in Why can't it display Chinese?:

        Please give me some advice

        Please provide more information/show the code...

        Q Offline
        Q Offline
        Qingshui Kong
        wrote on last edited by Qingshui Kong
        #3

        @jsulm
        07b421f6-ca5d-42b0-8806-f8355e58472c-image.png
        ab9aeb41-d77a-474a-b7c6-5b3e7abaee22-image.png
        899f865d-3781-4e3f-9cad-a16eb1366a90-image.png

        If I change the code to
        d89d1ad6-4fb1-417d-9a6f-f9b342638445-image.png
        The result changes to
        1ef1a8c0-3a0a-41b3-b081-7cd5aa35e494-image.png

        1 Reply Last reply
        0
        • Q Qingshui Kong

          Hello everyone,
          Could somebody help me?
          I create a QMainWindow. I set 'windowTitle' to some Chinese in the Designer. It works.
          But if I QTextCodec::setCodecForLocale();, it doesn't work.
          Please give me some advice.
          Thank you in advance.

          Q Offline
          Q Offline
          Qingshui Kong
          wrote on last edited by
          #4

          Could somebody give me some advice?

          1 Reply Last reply
          0
          • Q Offline
            Q Offline
            Qingshui Kong
            wrote on last edited by
            #5

            Nobody would like to give me any advice?
            I think maybe I should give up.

            jsulmJ 1 Reply Last reply
            0
            • Q Qingshui Kong

              Nobody would like to give me any advice?
              I think maybe I should give up.

              jsulmJ Offline
              jsulmJ Offline
              jsulm
              Lifetime Qt Champion
              wrote on last edited by
              #6

              @Qingshui-Kong Did you try to set window title using https://doc.qt.io/qt-5/qwidget.html#windowTitle-prop to see whether that makes a difference?

              https://forum.qt.io/topic/113070/qt-code-of-conduct

              Q 1 Reply Last reply
              1
              • jsulmJ jsulm

                @Qingshui-Kong Did you try to set window title using https://doc.qt.io/qt-5/qwidget.html#windowTitle-prop to see whether that makes a difference?

                Q Offline
                Q Offline
                Qingshui Kong
                wrote on last edited by
                #7

                @jsulm
                Thank you very much.
                But I think it doesn't work.
                f6c427bc-b517-46f5-9bd6-f9be4f5d5624-image.png

                If I don't set code for locale
                ad551857-388c-457a-a0f5-5593952a8511-image.png
                The result is
                ba2b38b2-1108-4bf7-a239-4fc8aaf2ade5-image.png

                If I set code for locale
                1a959068-e313-4c4e-b3f2-e0494846cc3c-image.png
                The result changes to
                168e113e-4285-4c34-924e-cef33967aa89-image.png

                jsulmJ 1 Reply Last reply
                0
                • Q Qingshui Kong

                  @jsulm
                  Thank you very much.
                  But I think it doesn't work.
                  f6c427bc-b517-46f5-9bd6-f9be4f5d5624-image.png

                  If I don't set code for locale
                  ad551857-388c-457a-a0f5-5593952a8511-image.png
                  The result is
                  ba2b38b2-1108-4bf7-a239-4fc8aaf2ade5-image.png

                  If I set code for locale
                  1a959068-e313-4c4e-b3f2-e0494846cc3c-image.png
                  The result changes to
                  168e113e-4285-4c34-924e-cef33967aa89-image.png

                  jsulmJ Offline
                  jsulmJ Offline
                  jsulm
                  Lifetime Qt Champion
                  wrote on last edited by
                  #8

                  @Qingshui-Kong Why do you use fromLocal8Bit?! Chinese can't be represented as 8bit encoding. Remove fromLocal8Bit and make sure your source code files are stored as UTF-8 (should be default in QtCreator).

                  https://forum.qt.io/topic/113070/qt-code-of-conduct

                  Q 1 Reply Last reply
                  1
                  • jsulmJ jsulm

                    @Qingshui-Kong Why do you use fromLocal8Bit?! Chinese can't be represented as 8bit encoding. Remove fromLocal8Bit and make sure your source code files are stored as UTF-8 (should be default in QtCreator).

                    Q Offline
                    Q Offline
                    Qingshui Kong
                    wrote on last edited by
                    #9

                    @jsulm
                    Thanks a lot.
                    My source code files are stored as GBK. I forgot the reason why I didn't use UTF-8. But there must be some problems. But I can't remember it.

                    After I store source code files as UTF-8, if I don't set code for locale, it works. If I set code for locale, it still dosen't work.

                    jsulmJ B 2 Replies Last reply
                    0
                    • Q Qingshui Kong

                      @jsulm
                      Thanks a lot.
                      My source code files are stored as GBK. I forgot the reason why I didn't use UTF-8. But there must be some problems. But I can't remember it.

                      After I store source code files as UTF-8, if I don't set code for locale, it works. If I set code for locale, it still dosen't work.

                      jsulmJ Offline
                      jsulmJ Offline
                      jsulm
                      Lifetime Qt Champion
                      wrote on last edited by
                      #10

                      @Qingshui-Kong Did you remove fromLocal8Bit?

                      https://forum.qt.io/topic/113070/qt-code-of-conduct

                      Q 1 Reply Last reply
                      0
                      • Q Qingshui Kong

                        @jsulm
                        Thanks a lot.
                        My source code files are stored as GBK. I forgot the reason why I didn't use UTF-8. But there must be some problems. But I can't remember it.

                        After I store source code files as UTF-8, if I don't set code for locale, it works. If I set code for locale, it still dosen't work.

                        B Offline
                        B Offline
                        Bonnie
                        wrote on last edited by
                        #11

                        @Qingshui-Kong
                        Try this macro QStringLiteral like:

                        setWindowTitle(QStringLiteral("小工具"));
                        

                        It helps me a lot.

                        Q 1 Reply Last reply
                        0
                        • jsulmJ jsulm

                          @Qingshui-Kong Did you remove fromLocal8Bit?

                          Q Offline
                          Q Offline
                          Qingshui Kong
                          wrote on last edited by
                          #12

                          @jsulm
                          Yes, I did.

                          1 Reply Last reply
                          0
                          • B Bonnie

                            @Qingshui-Kong
                            Try this macro QStringLiteral like:

                            setWindowTitle(QStringLiteral("小工具"));
                            

                            It helps me a lot.

                            Q Offline
                            Q Offline
                            Qingshui Kong
                            wrote on last edited by
                            #13

                            @Bonnie
                            Thanks.
                            I will try it.

                            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