可视化 C++ 类型
Visual Studio Natvis 框架可自定义本地类型在调试器变量窗口(如Locals 和Watch 窗口)以及DataTips 中的显示方式。您可以在.natvis 文件中添加可视化规则。默认情况下,用户特定文件位于%USERPROFILE%\Documents\Visual Studio 2022\Visualizers (或%USERPROFILE%\Documents\Visual Studio 18\Visualizers )。
您可以将调试器可视化嵌入LINK 生成的程序数据库 (PDB) 文件。该文件包含编译和链接项目时收集的类型和符号调试信息。
将 Natvis 文件嵌入 PDB 文件有以下好处:
- 可移植性--可视化逻辑与二进制文件一起传输,确保使用二进制文件的任何人(如其他开发人员、测试人员或用户)都能从自定义调试可视化中受益,而无需手动将 .natvis 文件复制到特定目录。
- 版本一致性--由于二进制文件是打包在一起的,因此可视化程序保证与二进制文件的版本相匹配。如果二进制文件发生变化,可视化器将反映正确的内部结构或变化,避免不匹配。
- 易于发布--在发布二进制文件时(例如,用于内部构建或外部发布),内嵌的 Natvis 文件会自动包含在内,因此无需单独发布,也无需在每台计算机上安装。
- 安全性--作为二进制文件一部分的 Natvis 文件更安全、更可控,因为用户无法修改它。
在 PDB 文件中嵌入 Natvis 文件
将 Natvis 文件嵌入 PDB 文件:
- 转到Extensions >Qt VS Tools >Options >Qt >General >Natvis 。

- 将Embed .natvis file into PDB 设为Enable 。
嵌入的 Natvis 文件优先于用户特定的 Natvis 文件。
另请参阅 调试应用程序。
© 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.