IDE Debug Helpers

From Qt Wiki
Revision as of 14:30, 23 February 2015 by Maintenance script (talk | contribs)
Jump to: navigation, search

IDE debug helpers

Qt Creator

Qt Creator directly supports introspection of all Qt Containers and QObject derived classes for Qt 4 and Qt 5.
User defined types can be supported in addition, see the Qt Creator documentation for details.

MS visual studio QString & QByteArray expansions

The new layout of QString in Qt 5 is hard to inspect using the debugger.
The following code can be added to autoexp.dat (c:files(x86)visual studio 9.0\common7\packages\debugger\autoexp.dat)
You should add it to the <nowiki&gt;[Visualizer]</nowiki&gt; section, before the STL/ATL containers.

; Qt types
preview ([(unsigned short*)$e.d + 2 + $e.offset,su])
stringview ([(unsigned short*)$e.d + 2 + $e.offset,sub])
preview ([$e.d])
preview ([(unsigned char*)$e.d + 4 + $e.offset,s])
stringview ([(unsigned char*)$e.d + 4 + $e.offset,sb])
preview ([$e.d])

Unfortunately, sizeof() cannot be used. That is why there is a constant 2 or 4 for the offset pointer.
For an x64 build, the sizes most likely need to be doubled.

MS Visual Studio 2012

There is a new way to visualize native type, see
";: for details.

Ready-made .natvis files are included in the "Visual Studio add-in&quot;:, and can be grabbed directly from "gitorious&quot;:

So we can visualize QString and some other types using .natvis file
&#40;save to file: USERPROFILEDocuments\Visual Studio 2012\Visualizers\Qt5.natvis&amp;#41;

&lt;?xml version="1.0&quot; encoding="utf-8&quot;?&gt;
<AutoVisualizer >

<Type Name="QString&quot;>
<DisplayString&gt;{(char*)d + d-&gt;offset,su}</DisplayString&gt;

<Type Name="QtPrivate::RefCount&quot;>

<Type Name="QBasicAtomicInteger&amp;amp;lt;int&amp;amp;gt;">

<Type Name="QTypedArrayData&amp;amp;lt;&amp;gt;">
<DisplayString&gt;{{Count = {size}}}</DisplayString&gt;
<Item Name="[size]">size&lt;/Item&gt;
<ValuePointer&gt;(iterator) ((char
)this + offset)</ValuePointer&gt;

<Type Name="QByteArray&quot;>

&lt;!— More Qt5 types… —&gt;


MS Visual Studio 2013

The ".natvis&quot; files introduced in MSVS2012 received some additional attention in MSVS2013: