AStyle格式化中文乱码
-
QtCreator16.0使用美化器AStyle格式化代码时,出现中文乱码的情况,下面图片一个是格式化前的你好,后面一张图片是格式化后的,我的相关信息如下,文件编码格式是utf-8无BOM,套件是minGW13.0,AStyle版本是3.6.7,自定义格式化内容如下图,强制输出编码注释了,因为会报错。
-
@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.
-
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.
-
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.
@Christian-Ehrlicher When using the clang-format beautification plugin for the downloaded LLVM 18.0.1 version, the problem is exactly the same.
-
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.
-
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.
@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-Ehrlicher Then how to check whether there is a problem with AStyle or clang-format on the command line, please describe it in detail。
@tomCJR said in AStyle格式化中文乱码:
please describe it in detail。
It's documented on the astyle website: https://astyle.sourceforge.net/astyle.html#_Usage
-
@tomCJR said in AStyle格式化中文乱码:
please describe it in detail。
It's documented on the astyle website: https://astyle.sourceforge.net/astyle.html#_Usage
@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.
-
So did you try it with astyle on the command line? Did it work there?
-
So did you try it with astyle on the command line? Did it work there?
@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
-
@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
@tomCJR said in AStyle格式化中文乱码:
but the garbled characters still exist
So, there IS a problem with Astyle.
-
@tomCJR said in AStyle格式化中文乱码:
but the garbled characters still exist
So, there IS a problem with Astyle.
@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
-
@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
@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?).
-
@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?).
@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.
-
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:
I think it works as expected. The text doesn't get distorted.
-
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:
I think it works as expected. The text doesn't get distorted.
@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:
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