Home > Enterprise >  Ambiguity between class-name and enumerator-values in C natvis
Ambiguity between class-name and enumerator-values in C natvis

Time:08-21

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-&gt;end - propertyNames.d-&gt;begin} }}</DisplayString>
    <Expand>
      <CustomListItems>
        <Variable Name="index" InitialValue="0" />
        <Variable Name="size" InitialValue="propertyNames.d-&gt;end - propertyNames.d-&gt;begin" />
        <Loop>
          <Break Condition="index >= size" />
          <Item Name="[{index}] {*reinterpret_cast&lt;const QByteArray*&gt;(_GetNameAsVoidPtr(index))}">
            {*reinterpret_cast&lt;const QVariant*&gt;(_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&lt;const QByteArray*&gt; with reinterpret_cast&lt;const Qt5Cored.dll::QByteArray*&gt;, removed const and other things - nothing worked. Then I printed these values in VS-Watch window and get the following picture: TypesEnums

And here I realised, that Qt has classes: class QByteArray and class QVariant, also, it has enum dynamic_properties_visualization

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.

  • Related