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 [http://doc-snapshot.qt-project.org/qtcreator-2.5/creator-debugging-helpers.html 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:\program files(x86)\microsoft visual studio 9.0\common7\packages\debugger\autoexp.dat)
You should add it to the <nowiki>[Visualizer]</nowiki> section, before the STL/ATL containers.

  1. ; Qt types
  2. QStringData{
  3.  preview  ([(unsigned short*)$e.d + 2 + $e.offset,su])
  4.  stringview ([(unsigned short*)$e.d + 2 + $e.offset,sub])
  5. }
  6.  preview  ([$e.d])
  7. }
  8. QByteArrayData{
  9.  preview  ([(unsigned char*)$e.d + 4 + $e.offset,s])
  10.  stringview ([(unsigned char*)$e.d + 4 + $e.offset,sb])
  11. }
  12.  preview  ([$e.d])
  13. }

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
http://code.msdn.microsoft.com/Writing-type-visualizers-2eae77a2 [code.msdn.microsoft.com] for details.

So we can visualize QString and some other types using .natvis file
(save to file: USERPROFILE\My Documents\Visual Studio 2012\Visualizers\Qt5.natvis)

  1. <?xml version="1.0" encoding="utf-8"?>
  2. <AutoVisualizer >
  3.  
  4.   <Type Name="QString">
  5.     <DisplayString>{(char*)d + d->offset,su}</DisplayString>
  6.   </Type>
  7.  
  8.   <Type Name="QtPrivate::RefCount">
  9.     <DisplayString>{atomic}</DisplayString>
  10.   </Type>
  11.  
  12.   <Type Name="QBasicAtomicInteger&lt;int&gt;">
  13.     <DisplayString>{_q_value}</DisplayString>
  14.   </Type>
  15.  
  16.   <Type Name="QTypedArrayData&lt;*&gt;">
  17.     <DisplayString>{{Count = {size}}}</DisplayString>
  18.     <Expand>
  19.       <Item Name="[size]">size</Item>
  20.       <ArrayItems>
  21.         <Size>size</Size>
  22.         <ValuePointer>(iterator) ((char*)this + offset)</ValuePointer>
  23.       </ArrayItems>
  24.     </Expand>
  25.   </Type>
  26.  
  27.   <Type Name="QByteArray">
  28.     <DisplayString>{*d}</DisplayString>
  29.   </Type>
  30.  
  31.   <!-- More Qt5 types...  -->
  32.  
  33. </AutoVisualizer>

Categories: