Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Qt Creator and other tools
  4. AStyle格式化中文乱码

AStyle格式化中文乱码

Scheduled Pinned Locked Moved Unsolved Qt Creator and other tools
17 Posts 4 Posters 706 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.
  • T Offline
    T Offline
    tomCJR
    wrote on 7 Apr 2025, 13:13 last edited by
    #1

    QtCreator16.0使用美化器AStyle格式化代码时,出现中文乱码的情况,下面图片一个是格式化前的你好,后面一张图片是格式化后的,我的相关信息如下,文件编码格式是utf-8无BOM,套件是minGW13.0,AStyle版本是3.6.7,自定义格式化内容如下图,强制输出编码注释了,因为会报错。
    PixPin_2025-04-03_14-02-57.png PixPin_2025-04-03_14-03-13.png PixPin_2025-04-07_21-06-46.png

    J 1 Reply Last reply 7 Apr 2025, 13:21
    0
    • T tomCJR
      7 Apr 2025, 13:13

      QtCreator16.0使用美化器AStyle格式化代码时,出现中文乱码的情况,下面图片一个是格式化前的你好,后面一张图片是格式化后的,我的相关信息如下,文件编码格式是utf-8无BOM,套件是minGW13.0,AStyle版本是3.6.7,自定义格式化内容如下图,强制输出编码注释了,因为会报错。
      PixPin_2025-04-03_14-02-57.png PixPin_2025-04-03_14-03-13.png PixPin_2025-04-07_21-06-46.png

      J Offline
      J Offline
      jsulm
      Lifetime Qt Champion
      wrote on 7 Apr 2025, 13:21 last edited by
      #2

      @tomCJR Please either post in English or in Chinese sub-forum

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

      T 1 Reply Last reply 7 Apr 2025, 13:28
      0
      • J jsulm
        7 Apr 2025, 13:21

        @tomCJR Please either post in English or in Chinese sub-forum

        T Offline
        T Offline
        tomCJR
        wrote on 7 Apr 2025, 13:28 last edited by
        #3

        @jsulm When using the beautifier AStyle to format code in QtCreator 16.0, there is a situation where Chinese characters become garbled. The following pictures show "你好" before and after formatting. My relevant information is as follows: the file encoding format is UTF-8 without BOM, the kit is minGW13.0, the AStyle version is 3.6.7, and the custom formatting content is as shown in the picture. The forced output encoding is commented out because it will cause an error.

        1 Reply Last reply
        0
        • C Offline
          C Offline
          Christian Ehrlicher
          Lifetime Qt Champion
          wrote on 7 Apr 2025, 13:40 last edited by
          #4

          Try astyle on the command line. I would guess your source code will get corrupted there too. Ask the astyle folks then as QtCreator only calls astyle on the soure file.

          Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
          Visit the Qt Academy at https://academy.qt.io/catalog

          T 1 Reply Last reply 7 Apr 2025, 13:59
          0
          • C Christian Ehrlicher
            7 Apr 2025, 13:40

            Try astyle on the command line. I would guess your source code will get corrupted there too. Ask the astyle folks then as QtCreator only calls astyle on the soure file.

            T Offline
            T Offline
            tomCJR
            wrote on 7 Apr 2025, 13:59 last edited by
            #5

            @Christian-Ehrlicher When using the clang-format beautification plugin for the downloaded LLVM 18.0.1 version, the problem is exactly the same.

            1 Reply Last reply
            0
            • C Offline
              C Offline
              Christian Ehrlicher
              Lifetime Qt Champion
              wrote on 7 Apr 2025, 14:11 last edited by
              #6

              Clang-format is also modifying the source file. Check on the command line. If you get the problem there too it's nothing QtCreator can do against.

              Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
              Visit the Qt Academy at https://academy.qt.io/catalog

              T 1 Reply Last reply 7 Apr 2025, 14:20
              0
              • C Christian Ehrlicher
                7 Apr 2025, 14:11

                Clang-format is also modifying the source file. Check on the command line. If you get the problem there too it's nothing QtCreator can do against.

                T Offline
                T Offline
                tomCJR
                wrote on 7 Apr 2025, 14:20 last edited by
                #7

                @Christian-Ehrlicher Then how to check whether there is a problem with AStyle or clang-format on the command line, please describe it in detail。

                C 1 Reply Last reply 7 Apr 2025, 15:14
                0
                • T tomCJR
                  7 Apr 2025, 14:20

                  @Christian-Ehrlicher Then how to check whether there is a problem with AStyle or clang-format on the command line, please describe it in detail。

                  C Offline
                  C Offline
                  Christian Ehrlicher
                  Lifetime Qt Champion
                  wrote on 7 Apr 2025, 15:14 last edited by
                  #8

                  @tomCJR said in AStyle格式化中文乱码:

                  please describe it in detail。

                  It's documented on the astyle website: https://astyle.sourceforge.net/astyle.html#_Usage

                  Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
                  Visit the Qt Academy at https://academy.qt.io/catalog

                  T 1 Reply Last reply 8 Apr 2025, 01:48
                  1
                  • C Christian Ehrlicher
                    7 Apr 2025, 15:14

                    @tomCJR said in AStyle格式化中文乱码:

                    please describe it in detail。

                    It's documented on the astyle website: https://astyle.sourceforge.net/astyle.html#_Usage

                    T Offline
                    T Offline
                    tomCJR
                    wrote on 8 Apr 2025, 01:48 last edited by
                    #9

                    @Christian-Ehrlicher I have tried the method you mentioned, and I have used the default style, but it still doesn't work, I also downloaded the same qt version on other computers, the same operation, the same errors, the version installed on the old computer in early 24, I have forgotten the specific version, but there is no such problem, no garbled code. And it makes no difference that system information includes anything else, screening for problems by control variables one by one, and it feels like qt itself is a problem.

                    1 Reply Last reply
                    0
                    • C Offline
                      C Offline
                      Christian Ehrlicher
                      Lifetime Qt Champion
                      wrote on 8 Apr 2025, 04:17 last edited by
                      #10

                      So did you try it with astyle on the command line? Did it work there?

                      Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
                      Visit the Qt Academy at https://academy.qt.io/catalog

                      T 1 Reply Last reply 11 Apr 2025, 05:31
                      0
                      • C Christian Ehrlicher
                        8 Apr 2025, 04:17

                        So did you try it with astyle on the command line? Did it work there?

                        T Offline
                        T Offline
                        tomCJR
                        wrote on 11 Apr 2025, 05:31 last edited by
                        #11

                        @Christian-Ehrlicher said in AStyle格式化中文乱码:

                        So did you try it with astyle on the command line? Did it work there?

                        I have tried the command line and there is no problem, but the garbled characters still exist. After downloading other versions of Astyle on some platforms and the official website, the program can run normally, but the Chinese garbled characters still exist

                        J 1 Reply Last reply 11 Apr 2025, 05:32
                        0
                        • T tomCJR
                          11 Apr 2025, 05:31

                          @Christian-Ehrlicher said in AStyle格式化中文乱码:

                          So did you try it with astyle on the command line? Did it work there?

                          I have tried the command line and there is no problem, but the garbled characters still exist. After downloading other versions of Astyle on some platforms and the official website, the program can run normally, but the Chinese garbled characters still exist

                          J Offline
                          J Offline
                          jsulm
                          Lifetime Qt Champion
                          wrote on 11 Apr 2025, 05:32 last edited by
                          #12

                          @tomCJR said in AStyle格式化中文乱码:

                          but the garbled characters still exist

                          So, there IS a problem with Astyle.

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

                          T 1 Reply Last reply 11 Apr 2025, 05:43
                          0
                          • J jsulm
                            11 Apr 2025, 05:32

                            @tomCJR said in AStyle格式化中文乱码:

                            but the garbled characters still exist

                            So, there IS a problem with Astyle.

                            T Offline
                            T Offline
                            tomCJR
                            wrote on 11 Apr 2025, 05:43 last edited by
                            #13

                            @jsulm said in AStyle格式化中文乱码:

                            @tomCJR said in AStyle格式化中文乱码:

                            but the garbled characters still exist

                            So, there IS a problem with Astyle.

                            Through my various attempts, I think that the high probability is the version of the qt tool, including the online platform download ah, he only listed the previous qt version (6.3 and 5 series), and no other old version information,But everyone else has no problem using Astyle the same version, the only difference is the version developed in qt, and mine is the latest version installed in March this year

                            J 1 Reply Last reply 11 Apr 2025, 06:09
                            0
                            • T tomCJR
                              11 Apr 2025, 05:43

                              @jsulm said in AStyle格式化中文乱码:

                              @tomCJR said in AStyle格式化中文乱码:

                              but the garbled characters still exist

                              So, there IS a problem with Astyle.

                              Through my various attempts, I think that the high probability is the version of the qt tool, including the online platform download ah, he only listed the previous qt version (6.3 and 5 series), and no other old version information,But everyone else has no problem using Astyle the same version, the only difference is the version developed in qt, and mine is the latest version installed in March this year

                              J Offline
                              J Offline
                              jsulm
                              Lifetime Qt Champion
                              wrote on 11 Apr 2025, 06:09 last edited by
                              #14

                              @tomCJR said in AStyle格式化中文乱码:

                              the version developed in qt

                              There is no Astyle version developed in Qt. QtCreator calls Astyle and if Astyle breaks something then this is not a QtCreator issue (you confirmed that you have same issue if you call Astyle directly, right?).

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

                              T 1 Reply Last reply 28 days ago
                              1
                              • J jsulm
                                11 Apr 2025, 06:09

                                @tomCJR said in AStyle格式化中文乱码:

                                the version developed in qt

                                There is no Astyle version developed in Qt. QtCreator calls Astyle and if Astyle breaks something then this is not a QtCreator issue (you confirmed that you have same issue if you call Astyle directly, right?).

                                T Offline
                                T Offline
                                tomCJR
                                wrote 28 days ago last edited by
                                #15

                                @jsulm said in AStyle格式化中文乱码:

                                @tomCJR said in AStyle格式化中文乱码:

                                the version developed in qt

                                There is no Astyle version developed in Qt. QtCreator calls Astyle and if Astyle breaks something then this is not a QtCreator issue (you confirmed that you have same issue if you call Astyle directly, right?).

                                I tried correctly and excluded the problems of astyle itself, and simply created a new text001.cpp file with obvious non-formatting features. After formatting this file through the command line tool, it was obviously formatted successfully after opening, and there was no garbled Chinese characters, so it proved that this was the related problem of qt for plug-ins.PixPin_2025-04-16_13-17-04.png

                                1 Reply Last reply
                                0
                                • cristian-adamC Online
                                  cristian-adamC Online
                                  cristian-adam
                                  wrote 28 days ago last edited by
                                  #16

                                  Just make sure that the tex codec for tools is set to UTF-8.

                                  I tested on Windows a project:

                                  • astyle
                                  • clang-format as external tool (is shipped with Qt Creator)
                                  • clang-format as part of the ClangFormat plugin

                                  See the result below:
                                  alt text

                                  I think it works as expected. The text doesn't get distorted.

                                  T 1 Reply Last reply 23 days ago
                                  0
                                  • cristian-adamC cristian-adam
                                    28 days ago

                                    Just make sure that the tex codec for tools is set to UTF-8.

                                    I tested on Windows a project:

                                    • astyle
                                    • clang-format as external tool (is shipped with Qt Creator)
                                    • clang-format as part of the ClangFormat plugin

                                    See the result below:
                                    alt text

                                    I think it works as expected. The text doesn't get distorted.

                                    T Offline
                                    T Offline
                                    tomCJR
                                    wrote 23 days ago last edited by
                                    #17

                                    @cristian-adam said in AStyle格式化中文乱码:

                                    Just make sure that the tex codec for tools is set to UTF-8.

                                    I tested on Windows a project:

                                    • astyle
                                    • clang-format as external tool (is shipped with Qt Creator)
                                    • clang-format as part of the ClangFormat plugin

                                    See the result below:
                                    alt text

                                    I think it works as expected. The text doesn't get distorted.

                                    I can't open the link you gave. Currently, I'm developing qt programs through Clion. Thank you

                                    1 Reply Last reply
                                    0

                                    1/17

                                    7 Apr 2025, 13:13

                                    • Login

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