【VS】【Qt】vs+ qt .natvis 失效问题
.natvis文件用于调试时候自定义显示自定义类型的可视化提示。
一般这类文件存在
C:\Program Files (x86)\Microsoft Visual Studio\2022\Enterprise\Common7\Packages\Debugger\Visualizers路径下。
.natvis文件的规则在此不介绍,详见官网:在调试器中创建本机对象的自定义视图
在natvis失效的时候,检查以下选项是否被勾选,如果是,则解除勾选
如果没勾选还是无法显示正确的自定义试图,则考虑是否natvis文件出错。
在此处选择详细,在debug的时候检查需要可视化的自定义类型,直接对日志搜索你的自定义类名如:“QString”。如果出现error,检查error项对应的问题。然后根据error更改对应的natvis文件
最常见的错误
任然报错"##NAMESPACE##::QPoint"无效,
解决方法:删除qt4.natvis内的所有"##NAMESPACE##::"字符,tios调试时可正常显示
qt4 qt5版本比较常见 此处记录一下qt4的。
记录 qt4.natvis
<?xml version="1.0" encoding="utf-8"?>
<AutoVisualizer xmlns="http://schemas.microsoft.com/vstudio/debugger/natvis/2010">
<!-- Large parts of this file were created by Ismo Haataja for Qt5.
I essentially ripped some parts away to get quite good support for my Qt4 installation.
-->
<Type Name="QString">
<DisplayString>{d->data,su}</DisplayString>
<StringView>d->data,su</StringView>
<Expand />
</Type>
<Type Name="QVector<*>">
<AlternativeType Name="QStack<*>"></AlternativeType>
<DisplayString>{{ size={p->size} }}</DisplayString>
<Expand>
<ArrayItems>
<Size>p->size</Size>
<ValuePointer>p->array</ValuePointer>
</ArrayItems>
</Expand>
</Type>
<Type Name="QByteArray">
<DisplayString>{d->data,s}</DisplayString>
</Type>
<Type Name="QList<*>">
<AlternativeType Name="QStringList"></AlternativeType>
<AlternativeType Name="QQueue<*>"></AlternativeType>
<DisplayString>{{ size={d->end - d->begin} }}</DisplayString>
<Expand>
<IndexListItems>
<Size>d->end - d->begin</Size>
<ValueNode>*reinterpret_cast<$T1*>((sizeof($T1) > sizeof(void*))
? reinterpret_cast<Node*>(d->array + d->begin + $i)->v
: reinterpret_cast<$T1*>(d->array + d->begin + $i))
</ValueNode>
</IndexListItems>
</Expand>
</Type>
<Type Name="QLinkedList<*>">
<DisplayString>{{ size={d->size} }}</DisplayString>
<Expand>
<LinkedListItems>
<Size>d->size</Size>
<HeadPointer>d->n</HeadPointer>
<NextPointer>n</NextPointer>
<ValueNode>(*(QLinkedListNode<$T1>*)this).t</ValueNode>
</LinkedListItems>
</Expand>
</Type>
<Type Name="QMapNode<*,*>">
<DisplayString>({key}, {value})</DisplayString>
<Expand>
<Item Name="[key]">key</Item>
<Item Name="[value]">value</Item>
</Expand>
</Type>
<Type Name="QMap<*,*>">
<AlternativeType Name="QMultiMap<*,*>"/>
<DisplayString>{{ size={d->size} }}</DisplayString>
<Expand>
<TreeItems>
<Size>d->size</Size>
<HeadPointer>d->header.left</HeadPointer>
<LeftPointer>left</LeftPointer>
<RightPointer>right</RightPointer>
<ValueNode>*((QMapNode<$T1,$T2>*)this)</ValueNode>
</TreeItems>
</Expand>
</Type>
<Type Name="QHashNode<*,*>">
<DisplayString Condition="next == 0">(empty)</DisplayString>
<DisplayString Condition="next != 0">({key}, {value})</DisplayString>
<Expand>
<Item Name="[key]" Condition="next != 0">key</Item>
<Item Name="[value]" Condition="next != 0">value</Item>
</Expand>
</Type>
<Type Name="QHash<*,*>">
<AlternativeType Name="QMultiHash<*,*>"/>
<DisplayString>{{ size={d->size} }}</DisplayString>
<Expand>
<IndexListItems>
<Size>d->numBuckets</Size>
<ValueNode>*((QHashNode<$T1,$T2>*)d->buckets[$i])</ValueNode>
</IndexListItems>
</Expand>
</Type>
<Type Name="QHashNode<*,QHashDummyValue>">
<DisplayString Condition="next == 0">(empty)</DisplayString>
<DisplayString Condition="next != 0">({key})</DisplayString>
<Expand>
<Item Name="[key]" Condition="next != 0">key</Item>
</Expand>
</Type>
<Type Name="QSet<*>">
<DisplayString>{{ size={q_hash.d->size} }}</DisplayString>
<Expand>
<ExpandedItem>q_hash</ExpandedItem>
</Expand>
</Type>
<Type Name="QVariant">
<!--Region DisplayString QVariant-->
<DisplayString Condition="d.type == QMetaType::Bool">{d.data.b}</DisplayString>
<DisplayString Condition="d.type == QMetaType::Int">{d.data.i}</DisplayString>
<DisplayString Condition="d.type == QMetaType::UInt">{d.data.u}</DisplayString>
<DisplayString Condition="d.type == QMetaType::LongLong">{d.data.ll}</DisplayString>
<DisplayString Condition="d.type == QMetaType::ULongLong">{d.data.ull}</DisplayString>
<DisplayString Condition="d.type == QMetaType::Double">{d.data.d}</DisplayString>
<DisplayString Condition="d.type == QMetaType::QChar">{d.data.c}</DisplayString>
<DisplayString Condition="d.type == QMetaType::QVariantMap">
{*((QMap<QString,QVariant>*)(d.is_shared ? d.data.shared->ptr
: reinterpret_cast<const void *>(&d.data.ptr)))}
</DisplayString>
<DisplayString Condition="d.type == QMetaType::QVariantList">
{*((QList<QVariant>*)(d.is_shared ? d.data.shared->ptr
: reinterpret_cast<const void *>(&d.data.ptr)))}
</DisplayString>
<DisplayString Condition="d.type == QMetaType::QString">
{*((QString*)(d.is_shared ? d.data.shared->ptr
: reinterpret_cast<const void *>(&d.data.ptr)))}
</DisplayString>
<DisplayString Condition="d.type == QMetaType::QStringList">
{*((QStringList*)(d.is_shared ? d.data.shared->ptr
: reinterpret_cast<const void *>(&d.data.ptr)))}
</DisplayString>
<DisplayString Condition="d.type == QMetaType::QByteArray">
{*((QByteArray*)(d.is_shared ? d.data.shared->ptr
: reinterpret_cast<const void *>(&d.data.ptr)))}
</DisplayString>
<DisplayString Condition="d.type == QMetaType::QBitArray">
{*((QBitArray*)(d.is_shared ? d.data.shared->ptr
: reinterpret_cast<const void *>(&d.data.ptr)))}
</DisplayString>
<DisplayString Condition="d.type == QMetaType::QDate">
{*((QDate*)(d.is_shared ? d.data.shared->ptr
: reinterpret_cast<const void *>(&d.data.ptr)))}
</DisplayString>
<DisplayString Condition="d.type == QMetaType::QTime">
{*((QTime*)(d.is_shared ? d.data.shared->ptr
: reinterpret_cast<const void *>(&d.data.ptr)))}
</DisplayString>
<DisplayString Condition="d.type == QMetaType::QDateTime">DateTime</DisplayString>
<DisplayString Condition="d.type == QMetaType::QUrl">Url</DisplayString>
<DisplayString Condition="d.type == QMetaType::QLocale">Locale</DisplayString>
<DisplayString Condition="d.type == QMetaType::QRect">
{*((QRect*)(d.is_shared ? d.data.shared->ptr
: reinterpret_cast<const void *>(&d.data.ptr)))}
</DisplayString>
<DisplayString Condition="d.type == QMetaType::QRectF">
{*((QRectF*)(d.is_shared ? d.data.shared->ptr
: reinterpret_cast<const void *>(&d.data.ptr)))}
</DisplayString>
<DisplayString Condition="d.type == QMetaType::QSize">
{*((QSize*)(d.is_shared ? d.data.shared->ptr
: reinterpret_cast<const void *>(&d.data.ptr)))}
</DisplayString>
<DisplayString Condition="d.type == QMetaType::QSizeF">
{*((QSizeF*)(d.is_shared ? d.data.shared->ptr
: reinterpret_cast<const void *>(&d.data.ptr)))}
</DisplayString>
<DisplayString Condition="d.type == QMetaType::QLine">
{*((QLine*)(d.is_shared ? d.data.shared->ptr
: reinterpret_cast<const void *>(&d.data.ptr)))}
</DisplayString>
<DisplayString Condition="d.type == QMetaType::QLineF">
{*((QLineF*)(d.is_shared ? d.data.shared->ptr
: reinterpret_cast<const void *>(&d.data.ptr)))}
</DisplayString>
<DisplayString Condition="d.type == QMetaType::QPoint">
{*((QPoint*)(d.is_shared ? d.data.shared->ptr
: reinterpret_cast<const void *>(&d.data.ptr)))}
</DisplayString>
<DisplayString Condition="d.type == QMetaType::QPointF">
{*((QPointF*)(d.is_shared ? d.data.shared->ptr
: reinterpret_cast<const void *>(&d.data.ptr)))}
</DisplayString>
<DisplayString Condition="d.type == QMetaType::QRegExp">RegExp</DisplayString>
<DisplayString Condition="d.type == QMetaType::QVariantHash">
{*((QHash<QString,QVariant>*)(d.is_shared ? d.data.shared->ptr
: reinterpret_cast<const void *>(&d.data.ptr)))}
</DisplayString>
<DisplayString Condition="d.type == QMetaType::QEasingCurve">EasingCurve</DisplayString>
<DisplayString Condition="d.type == QMetaType::LastCoreType">LastCoreType</DisplayString>
<DisplayString Condition="d.type == QMetaType::QFont">Font</DisplayString>
<DisplayString Condition="d.type == QMetaType::QPixmap">Pixmap</DisplayString>
<DisplayString Condition="d.type == QMetaType::QBrush">Brush</DisplayString>
<DisplayString Condition="d.type == QMetaType::QColor">Color</DisplayString>
<DisplayString Condition="d.type == QMetaType::QPalette">Palette</DisplayString>
<DisplayString Condition="d.type == QMetaType::QImage">Image</DisplayString>
<DisplayString Condition="d.type == QMetaType::QPolygon">Polygon</DisplayString>
<DisplayString Condition="d.type == QMetaType::QRegion">Region</DisplayString>
<DisplayString Condition="d.type == QMetaType::QBitmap">Bitmap</DisplayString>
<DisplayString Condition="d.type == QMetaType::QCursor">Cursor</DisplayString>
<DisplayString Condition="d.type == QMetaType::QKeySequence">KeySequence</DisplayString>
<DisplayString Condition="d.type == QMetaType::QPen">Pen</DisplayString>
<DisplayString Condition="d.type == QMetaType::QTextLength">TextLength</DisplayString>
<DisplayString Condition="d.type == QMetaType::QTextFormat">TextFormat</DisplayString>
<DisplayString Condition="d.type == QMetaType::QMatrix">Matrix</DisplayString>
<DisplayString Condition="d.type == QMetaType::QTransform">Transform</DisplayString>
<DisplayString Condition="d.type == QMetaType::QMatrix4x4">Matrix4x4</DisplayString>
<DisplayString Condition="d.type == QMetaType::QVector2D">Vector2D</DisplayString>
<DisplayString Condition="d.type == QMetaType::QVector3D">Vector3D</DisplayString>
<DisplayString Condition="d.type == QMetaType::QVector4D">Vector4D</DisplayString>
<DisplayString Condition="d.type == QMetaType::QQuaternion">Quaternion</DisplayString>
<DisplayString Condition="d.type == QMetaType::QIcon">Icon</DisplayString>
<DisplayString Condition="d.type == QMetaType::LastGuiType">LastGuiType</DisplayString>
<DisplayString Condition="d.type == QMetaType::QSizePolicy">SizePolicy</DisplayString>
<DisplayString Condition="d.type == QMetaType::User">UserType</DisplayString>
<DisplayString>Unknown type</DisplayString>
<!--End region DisplayString QVariant-->
<!--Region DisplayView QVariant-->
<StringView Condition="d.type == QMetaType::QChar">d.data.c</StringView>
<StringView Condition="d.type == QMetaType::QString">
*((QString*)(d.is_shared ? d.data.shared->ptr
: reinterpret_cast<const void *>(&d.data.ptr)))
</StringView>
<StringView Condition="d.type == QMetaType::QByteArray">
*((QByteArray*)(d.is_shared ? d.data.shared->ptr
: reinterpret_cast<const void *>(&d.data.ptr)))
</StringView>
<!--End region DisplayView QVariant-->
<!--Region Expand QVariant-->
<Expand>
<ExpandedItem Condition="d.type == QMetaType::QVariantMap">
*((QMap<QString,QVariant>*)(d.is_shared ? d.data.shared->ptr
: reinterpret_cast<const void *>(&d.data.ptr)))
</ExpandedItem>
<ExpandedItem Condition="d.type == QMetaType::QVariantList">
*((QList<QVariant>*)(d.is_shared ? d.data.shared->ptr
: reinterpret_cast<const void *>(&d.data.ptr)))
</ExpandedItem>
<ExpandedItem Condition="d.type == QMetaType::QString">
*((QString*)(d.is_shared ? d.data.shared->ptr
: reinterpret_cast<const void *>(&d.data.ptr)))
</ExpandedItem>
<ExpandedItem Condition="d.type == QMetaType::QStringList">
*((QStringList*)(d.is_shared ? d.data.shared->ptr
: reinterpret_cast<const void *>(&d.data.ptr)))
</ExpandedItem>
<ExpandedItem Condition="d.type == QMetaType::QByteArray">
*((QByteArray*)(d.is_shared ? d.data.shared->ptr
: reinterpret_cast<const void *>(&d.data.ptr)))
</ExpandedItem>
<ExpandedItem Condition="d.type == QMetaType::QBitArray">
*((QBitArray*)(d.is_shared ? d.data.shared->ptr
: reinterpret_cast<const void *>(&d.data.ptr)))
</ExpandedItem>
<ExpandedItem Condition="d.type == QMetaType::QDate">
*((QDate*)(d.is_shared ? d.data.shared->ptr
: reinterpret_cast<const void *>(&d.data.ptr)))
</ExpandedItem>
<ExpandedItem Condition="d.type == QMetaType::QTime">
*((QTime*)(d.is_shared ? d.data.shared->ptr
: reinterpret_cast<const void *>(&d.data.ptr)))
</ExpandedItem>
<ExpandedItem Condition="d.type == QMetaType::QRect">
*((QRect*)(d.is_shared ? d.data.shared->ptr
: reinterpret_cast<const void *>(&d.data.ptr)))
</ExpandedItem>
<ExpandedItem Condition="d.type == QMetaType::QRectF">
*((QRectF*)(d.is_shared ? d.data.shared->ptr
: reinterpret_cast<const void *>(&d.data.ptr)))
</ExpandedItem>
<ExpandedItem Condition="d.type == QMetaType::QSize">
*((QSize*)(d.is_shared ? d.data.shared->ptr
: reinterpret_cast<const void *>(&d.data.ptr)))
</ExpandedItem>
<ExpandedItem Condition="d.type == QMetaType::QSizeF">
*((QSizeF*)(d.is_shared ? d.data.shared->ptr
: reinterpret_cast<const void *>(&d.data.ptr)))
</ExpandedItem>
<ExpandedItem Condition="d.type == QMetaType::QLine">
*((QLine*)(d.is_shared ? d.data.shared->ptr
: reinterpret_cast<const void *>(&d.data.ptr)))
</ExpandedItem>
<ExpandedItem Condition="d.type == QMetaType::QLineF">
*((QLineF*)(d.is_shared ? d.data.shared->ptr
: reinterpret_cast<const void *>(&d.data.ptr)))
</ExpandedItem>
<ExpandedItem Condition="d.type == QMetaType::QPoint">
*((QPoint*)(d.is_shared ? d.data.shared->ptr
: reinterpret_cast<const void *>(&d.data.ptr)))
</ExpandedItem>
<ExpandedItem Condition="d.type == QMetaType::QPointF">
*((QPointF*)(d.is_shared ? d.data.shared->ptr
: reinterpret_cast<const void *>(&d.data.ptr)))
</ExpandedItem>
<ExpandedItem Condition="d.type == QMetaType::QVariantHash">
*((QHash<QString,QVariant>*)(d.is_shared ? d.data.shared->ptr
: reinterpret_cast<const void *>(&d.data.ptr)))
</ExpandedItem>
</Expand>
<!--End region Expand QVariant-->
</Type>
</AutoVisualizer>