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

ぃ、小莉子 提交于 2019-11-30 06:42:00

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

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...

For me, in Qt5 and Visual Studio 2012, i just did this:

Project options -> debugging -> Debugger type -> Set it from Auto to Mixed.

Not the strings are displayed in the watch.

For Visual Studio 2015...

Tools > Options > Debugging > General > Check "Use Native Compatibility Mode"

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!