I want to create a natvis for QObject
. There are dynamic properties concepts, which stored in form
QList<QByteArray> propertyNames;
QVector<QVariant> propertyValues;
and I want to group them and visualize as a map(key-value items).
My natvis is pretty simple (for illustration purposes, I replaced all complex logic of getting data from QList
and QVector
with _GetNameAsVoidPtr
and _GetValueAsVoidPtr
):
<Type Name="QObject">
...
<Synthetic Name="dynamic_properties">
<DisplayString>{{ size = {propertyNames.d->end - propertyNames.d->begin} }}</DisplayString>
<Expand>
<CustomListItems>
<Variable Name="index" InitialValue="0" />
<Variable Name="size" InitialValue="propertyNames.d->end - propertyNames.d->begin" />
<Loop>
<Break Condition="index >= size" />
<Item Name="[{index}] {*reinterpret_cast<const QByteArray*>(_GetNameAsVoidPtr(index))}">
{*reinterpret_cast<const QVariant*>(_GetValueAsVoidPtr(index))}
</Item>
<Exec> index</Exec>
</Loop>
</CustomListItems>
</Expand>
</Synthetic>
...
</Type>
I get the following error:
Natvis: QObject.natvis(217,21): Error: constant "QByteArray" is not a type name
Error while evaluating '*reinterpret_cast<const QByteArray*>(_GetNameAsVoidPtr(index))' in the context of type 'Qt5Cored.dll!QObject'.
Natvis: QObject.natvis(217,21): Error: constant "QVariant" is not a type name
Error while evaluating '*reinterpret_cast<const QVariant*>(_GetValueAsVoidPtr(index))' in the context of type 'Qt5Widgetsd.dll!QObject'.
I tried to replace reinterpret_cast<const QByteArray*>
with reinterpret_cast<const Qt5Cored.dll::QByteArray*>
, removed const
and other things - nothing worked. Then I printed these values in VS-Watch window and get the following picture:
And here I realised, that Qt has classes: class QByteArray
and class QVariant
,
also, it has enum
But my question is still relevant. Is there a way to convince visual_studio/natvis that QVariant
is a typename, not a QMetaType::Type::QVariant
.