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 725 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 tomCJR

    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

    jsulmJ Online
    jsulmJ Online
    jsulm
    Lifetime Qt Champion
    wrote on 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
    0
    • jsulmJ jsulm

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

      T Offline
      T Offline
      tomCJR
      wrote on 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
      • Christian EhrlicherC Offline
        Christian EhrlicherC Offline
        Christian Ehrlicher
        Lifetime Qt Champion
        wrote on 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
        0
        • Christian EhrlicherC Christian Ehrlicher

          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 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
          • Christian EhrlicherC Offline
            Christian EhrlicherC Offline
            Christian Ehrlicher
            Lifetime Qt Champion
            wrote on 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
            0
            • Christian EhrlicherC Christian Ehrlicher

              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 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。

              Christian EhrlicherC 1 Reply Last reply
              0
              • T tomCJR

                @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。

                Christian EhrlicherC Offline
                Christian EhrlicherC Offline
                Christian Ehrlicher
                Lifetime Qt Champion
                wrote on 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
                1
                • Christian EhrlicherC Christian Ehrlicher

                  @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 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
                  • Christian EhrlicherC Offline
                    Christian EhrlicherC Offline
                    Christian Ehrlicher
                    Lifetime Qt Champion
                    wrote on 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
                    0
                    • Christian EhrlicherC Christian Ehrlicher

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

                      T Offline
                      T Offline
                      tomCJR
                      wrote on 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

                      jsulmJ 1 Reply Last reply
                      0
                      • T tomCJR

                        @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

                        jsulmJ Online
                        jsulmJ Online
                        jsulm
                        Lifetime Qt Champion
                        wrote on 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
                        0
                        • jsulmJ jsulm

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

                          but the garbled characters still exist

                          So, there IS a problem with Astyle.

                          T Offline
                          T Offline
                          tomCJR
                          wrote on 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

                          jsulmJ 1 Reply Last reply
                          0
                          • T tomCJR

                            @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

                            jsulmJ Online
                            jsulmJ Online
                            jsulm
                            Lifetime Qt Champion
                            wrote on 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
                            1
                            • jsulmJ jsulm

                              @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 on 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 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
                                0
                                • cristian-adamC cristian-adam

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

                                  • Login

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