This is the default behavior of Visual Studio in any version. Since it does not know how to present the object QString
, it presents its internal content in the best way it can.
What happens is that when the Qty Visual Studio Add-in, it installs a custom viewer into your VS allowing the QStrings
are easily seen at debugging time.
If for some reason you can’t install Qt VS Add-in (if your VS is the version Express, for example), you can install the viewer manually. Do so:
- Go to the Add-in repository on Github, browse and download the file with extension
.natvis
the version of Qt you use. For example, this is version 5 file qt.
- Copy this file to the folder
<MyDocuments>\Visual Studio <versão>\Visualizers
. In the case of Visual Studio 2015 that I have here, for example, is the folder C:\Users\Luiz\Documents\Visual Studio 2015\Visualizers
. It probably already exists, but if it doesn’t exist, it can create it.
- Restart Visual Studio.
After restarting, the strings using QString
will be easily seen in the debugger:
Note that the file .natvis
also contains viewers for other Qt objects. It is too big to fully reproduce here, but just for reference, it has this format in version 5:
<?xml version="1.0" encoding="utf-8"?>
<AutoVisualizer xmlns="http://schemas.microsoft.com/vstudio/debugger/natvis/2010">
<Type Name="QPoint">
<AlternativeType Name="QPointF"/>
<DisplayString>{{ x = {xp}, y = {yp} }}</DisplayString>
<Expand>
<Item Name="[x]">xp</Item>
<Item Name="[y]">yp</Item>
</Expand>
</Type>
<Type Name="QRect">
<DisplayString>{{ x = {x1}, y = {y1}, width = {x2 - x1 + 1}, height = {y2 - y1 + 1} }}</DisplayString>
<Expand>
<Item Name="[x]">x1</Item>
<Item Name="[y]">y1</Item>
<Item Name="[width]">x2 - x1 + 1</Item>
<Item Name="[height]">y2 - y1 + 1</Item>
</Expand>
</Type>
<Type Name="QSize">
<AlternativeType Name="QSizeF"/>
<DisplayString>{{ width = {wd}, height = {ht} }}</DisplayString>
<Expand>
<Item Name="[width]">wd</Item>
<Item Name="[height]">ht</Item>
</Expand>
</Type>
. . .
<Type Name="QString">
<DisplayString>{((reinterpret_cast<unsigned short*>(d)) + d->offset / 2),sub}</DisplayString>
<StringView>((reinterpret_cast<unsigned short*>(d)) + d->offset / 2),sub</StringView>
<Expand>
<Item Name="[size]">d->size</Item>
<Item Name="[referenced]">d->ref.atomic._q_value</Item>
<ArrayItems>
<Size>d->size</Size>
<ValuePointer>((reinterpret_cast<unsigned short*>(d)) + d->offset / 2),c</ValuePointer>
</ArrayItems>
</Expand>
</Type>
. . .
</AutoVisualizer>
To learn more about native Visual Studio viewers, see the documentation.