Qt6 and Visual C++ 2022 Questions about handling sjis files

Asked 1 years ago, Updated 1 years ago, 263 views

I am trying to port a project to Qt6 that has been successfully compiled and executed in Qt5 and Visual C++ 2022 environments, but I get some compilation errors in the Japanese string.

Based on the message, it seems that the source file encoded with sjis is compiled thinking that it is UTF-8 and an error is generated in the Japanese string in the source.Looking further, it seems that this is how it works by adding the option /utf-8 to the command line of the compilation.Saving the source file again with utf8 eliminates errors.

C/C++-> I checked all the options and command lines in the project properties, but I don't know where /utf-8 is specified.However, if you specify /source-charset:utf-8 as an additional option, this option cannot be used with /utf-8, so there is no doubt that /utf-8 is specified somewhere, and I think Qt VS Tools is bad.

How do I remove /utf-8 from the option so that I can compile the sjis file as I did in Qt5?

I think the proper way is to convert all sources to utf8, but I'm a little hesitant because there are so many.Thank you for your cooperation.

Now that you have commented, I will add the actual error message.

1>C:\Users\foo\source\boo.cpp(1,1): warning C4828: The file contains characters that cannot be used by the current source character set (code page 65001) starting with offset 0xa57.

appears multiple in all of the sjis files. In the ,

1>C:\Users\foo\source\boo.cpp (81,15):error C2001:constant follows line 2.

stops compiling.The above message is not in Qt5 version.Also, saving boo.cpp with UTF-8 erases the errors associated with boo.cpp.

Try the project properties ->C/C++-> command line, and specify /source-charset:utf-8 as the additional option.

1>cl: Command line error D8016: Command line options '/utf-8' and '/source-charset:utf-8' cannot be specified at the same time

appears and the build fails.However, all options in the same place are

/permissive-/MP/ifcOutput"x64\Debug"/GS/W1/Zc:wchar_t/Zi/Gm-/Od/Fd"x64\Debug\vc143.pdb"/Zc:inline/fp:precise /D "_WINDOWS" /D "UNICODE" /D "_UNICODE" /D "WIN32" /D "_ENABLE_EXTENDED_ALIGNED_STORAGE" /D "WIN64" /D "QT_OPENGLWIDGETS_LIB" /D "QT_WIDGETS_LIB" /D "QT_OPENGL_LIB" /D "QT_SVG_LIB" /D "QT_GUI_LIB" /D "QT_NETWORK_LIB" /D "QT_CONCURRENT_LIB" /D "QT_CORE_LIB" /errorReport:prompt /WX- /Zc:forScope /Gd /MDd /std:c++17 /FC /Fa"x64\Debug" /EHsc /nologo /Fo"x64\Debug" /Fp"x64\Debug\boo.pch"/diagnostics:column

I can't find /utf-8.The /I option has been removed above.As for /D "UNICODE"/D "_UNICODE", I think there is no problem because it comes with the Qt5 version without any problems.Removing the "Inheritance from Parent or Project" check mark does not change the symptom.I would appreciate it if you could let me know if there are any other necessary information in the comments.

This is a postscript.
When I tried adding /utf-8 to the compilation option in the Qt5 version, which was compiled without any problems, I got the same error as the Qt6 version.Therefore, I think the problem is that the Qt6 version has added the /utf-8 option.After all, Qt5->Qt6 just changed the library, and I didn't change the options, so I can't believe it.However, I suspect that if Qt VS Tools is Qt6, /utf-8 is added to the option without permission.Even if I display all the options in VS, I suspect that it is only showing what I have specified and that it has been added to it. What do you think?

qt visual-c++ japanese

2022-10-24 00:00

1 Answers

In Qt6.0, the CMake command qt_allow_non_utf8_sources appears to have been introduced.This means that the Qt source code should be encoded as UTF-8, otherwise this command should specify it.

However, this was done with CMake and we did not know how it was handled in the Qt VS Tools case in question.However, given the status of the question, Qt VS Tools may consider the source code to be UTF-8 just like the CMake side, and the compilation option /utf-8 may be specified somewhere.

I'm just showing what I've specified, and I suspect it's being added to it.

There is a possibility.For this, you can change the logging level in the Options dialog box: MSBuild Project Build Output Details in Projects > Build/Run.By increasing the logging level, you can see which command line you actually launched, so you can see if there are any relevant options, such as /utf-8.


2022-10-24 00:00

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.