It seems that visualizing Qt5.6 QStrings in the Visual Studio 2015 debugger does not work with the standard way of QString visualization (adding a natvis to Visual Studio 2015\Visualizers) as one did in Visual Studio 2013 and before. Is this correct? Has anyone managed to add QString visualization in VS 2015?
3 Answers
I had been doing this successfully in VS 2015 with Qt 5.6 for a while, although either update 3 or an addition I made started screwing things up. This is the definition I used:
<Type Name="QString">
<DisplayString IncludeView="nq">{((reinterpret_cast<unsigned short*>(d)) + d->offset / 2),sub}</DisplayString>
<DisplayString ExcludeView="nq">"{((reinterpret_cast<unsigned short*>(d)) + d->offset / 2),sub}"</DisplayString>
<StringView>((reinterpret_cast<unsigned short*>(d)) + d->offset / 2),sub</StringView>
<Expand HideRawView="true">
<Item ExcludeView="simple" Name="[size]">d->size</Item>
<Item ExcludeView="simple" Name="[referenced]">d->ref.atomic._q_value</Item>
<ArrayItems ExcludeView="simple">
<Size>d->size</Size>
<ValuePointer>((reinterpret_cast<unsigned short*>(d)) + d->offset / 2),c</ValuePointer>
</ArrayItems>
</Expand>
</Type>
If you have the Qt5.natvis file that comes with the now deprecated VS Addin, I added it to my solution so I could modify it. There were a number of things that didn't work quite right, and I've been adding plenty more types as I go.
Note: I added a view to display the string without quotes, and added the ability to use view(simple)
elsewhere to suppress the children, but I think this is otherwise unmodified.
If you're still having trouble, you can turn on warning or verbose logging for Natvis:

- 1,784
- 20
- 32
The easiest automatic way to add debugging compatibility to Visual Studio for Qt is installing the Qt Visual Studio Tools and setting the Debugger Type to "Mixed" in project properties -> Configuration Properties -> Debugging.
Tested for Qt 5.9.1 and Visual Studio 2015

- 2,871
- 14
- 25