本页内容

qt_allow_non_utf8_sources

防止强制将 Windows 上的源文件视为 UTF-8 格式。

该命令定义在Qt6 包的Core 组件中,可按如下方式加载:

find_package(Qt6 REQUIRED COMPONENTS Core)

该命令于 Qt 6.0 中引入。

语法

qt_allow_non_utf8_sources(target)

如果禁用了无版本号的命令,请改用qt6_allow_non_utf8_sources() 。它支持与本命令相同的参数集。

说明

在使用某些 Windows 编译器进行构建时,链接到 Qt 库的目标会使用一些标志,强制编译器将其源文件视为 UTF-8 格式。目前,此功能已在 Visual Studio 和 Intel 编译器中实现。您可以通过调用qt_allow_non_utf8_sources() 并将目标作为参数传递,按目标逐个禁用此行为。

注意:这 不会改变诸如QString 之类的类的运行时行为(其来自const char * 的构造函数需要正确编码的 UTF-8 输入)。请使用QT_NO_CAST_FROM_ASCII 和QT_RESTRICTED_CAST_FROM_ASCII 宏来帮助识别此类代码。

{cmake-target-property-QT_NO_UTF8_SOURCE}

另请参阅 qt_disable_unicode_defines()。

© 2026 The Qt Company Ltd. Documentation contributions included herein are the copyrights of their respective owners. The documentation provided herein is licensed under the terms of the GNU Free Documentation License version 1.3 as published by the Free Software Foundation. Qt and respective logos are trademarks of The Qt Company Ltd. in Finland and/or other countries worldwide. All other trademarks are property of their respective owners.