Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Visual studio 2012 and Qt4.8.5 : How to see QString contents in debug mode.

I use visual studio 2012 and Qt4.8.5, unfortunately I can not see the QString text variable when I work in debug mode. Is someone has a tip allow it ? Qt4.8.5 plug-in doesn't exist for VS2012.

Thank a lot

Xavier

like image 721
xavSIB Avatar asked Mar 11 '14 11:03

xavSIB


People also ask

How do I show variables in Debug in Visual Studio?

Hover over a variable to see its value. When stopped in the debugger hover the mouse cursor over the variable you want to look at. The DataTip will appear showing you the value of that variable. If the variable is an object, you can expand the object by clicking on the arrow to see the elements of that object.

How do I set Debug configuration in Visual Studio?

In Solution Explorer, right-click the project and choose Properties. In the side pane, choose Build (or Compile in Visual Basic). In the Configuration list at the top, choose Debug or Release. Select the Advanced button (or the Advanced Compile Options button in Visual Basic).


2 Answers

There is a quick and explicit solution (MSVC native, no need for plugins nor setting up .dat files), see my answer from here

Say you have QString str (Qt4), then add to the debugger watch window:

((str).d)->array,su 

the appendix ,su tells the debugger to interpret the data as unicode and null terminated string.

Note: For a Qt5 QString str it could be

(char*)str.d + str.d->offset,su
like image 105
DomTomCat Avatar answered Dec 01 '22 00:12

DomTomCat


the autoexp.dat is not used unless you set the Debugger options to "Enable native Edit and Continue"

here is my natvis implementation of the QString for 4.8.5 (expands only the first 25 chars)

<Type Name="QString">
    <DisplayString>"{d->data,sub}"</DisplayString>
    <StringView>d->data,sub</StringView>
    <Expand>
        <Item Condition="d->size &gt;= 0" Name="[size]">d->size</Item>
        <Item Condition="d->size &gt; 0" Name="[referenced]">d->ref._q_value</Item>
        <ArrayItems Condition="d->size&lt;=25">
            <Size>d->size</Size>
            <ValuePointer>d->data,c</ValuePointer>
        </ArrayItems>
        <ArrayItems Condition="d->size&gt;25">
            <Size>25</Size>
            <ValuePointer>d->data,c</ValuePointer>
        </ArrayItems>
        <Item Condition="d->size&gt;25" Name="...">d->size - 25</Item>
    </Expand>
</Type>

at least the qt4.natvis can coexist with the qt5.natvis as one or the other fails to load correctly...

like image 21
user3684363 Avatar answered Dec 01 '22 01:12

user3684363