This is the default behavior of Visual Studio in any version. Since it does not know how to display the QString
object, it presents its internal contents as best it can.
What happens is that when you install the Qt Visual Studio Add-in , it installs a custom viewer on the your VS allowing QStrings
to be easily seen in debug time.
If for some reason you can not install the Qt VS Add-in (if your VS is the Express version, for example), you can install the viewer manually. Here's how:
Go to the Github add-in repository , browse to and download the file with .natvis
of the Qt version it uses. For example, this is the version 5 file of Qt .
Copy this file to the <MyDocuments>\Visual Studio <versão>\Visualizers
folder. In the case of Visual Studio 2015 that I have here, for example, is the C:\Users\Luiz\Documents\Visual Studio 2015\Visualizers
folder. It probably already exists, but if it does not exist you can create it.
Restart Visual Studio.
After restart, strings using QString
will be easily seen in the debugger:
Notethatthe
.natvis
filealsocontainsviewersforotherQtobjects.Itistoolargetoreproducecompletelyhere,butforreferenceonly,ithasthisformatinversion5:
<?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 .