user3640262
user3640262

Reputation: 57

View Qt5.6 QStrings in Visual Studio 2015 Debugger

It seems that visualizing Qt5.6 QStrings in the Visual Studio 2015 debugger does not work with the standard way of QString visualization (adding a natvis to Visual Studio 2015\Visualizers) as one did in Visual Studio 2013 and before. Is this correct? Has anyone managed to add QString visualization in VS 2015?

Upvotes: 0

Views: 5426

Answers (3)

RoQuOTriX
RoQuOTriX

Reputation: 3001

The easiest automatic way to add debugging compatibility to Visual Studio for Qt is installing the Qt Visual Studio Tools and setting the Debugger Type to "Mixed" in project properties -> Configuration Properties -> Debugging.

Tested for Qt 5.9.1 and Visual Studio 2015

Upvotes: 2

Cong Ma
Cong Ma

Reputation: 1311

You can try Qt Visual Studio Tools

Upvotes: 3

John Neuhaus
John Neuhaus

Reputation: 1937

I had been doing this successfully in VS 2015 with Qt 5.6 for a while, although either update 3 or an addition I made started screwing things up. This is the definition I used:

<Type Name="QString">
    <DisplayString IncludeView="nq">{((reinterpret_cast&lt;unsigned short*&gt;(d)) + d->offset / 2),sub}</DisplayString>
    <DisplayString ExcludeView="nq">"{((reinterpret_cast&lt;unsigned short*&gt;(d)) + d->offset / 2),sub}"</DisplayString>
    <StringView>((reinterpret_cast&lt;unsigned short*&gt;(d)) + d->offset / 2),sub</StringView>
    <Expand HideRawView="true">
        <Item ExcludeView="simple" Name="[size]">d-&gt;size</Item>
        <Item ExcludeView="simple" Name="[referenced]">d-&gt;ref.atomic._q_value</Item>
        <ArrayItems ExcludeView="simple">
            <Size>d-&gt;size</Size>
            <ValuePointer>((reinterpret_cast&lt;unsigned short*&gt;(d)) + d->offset / 2),c</ValuePointer>
        </ArrayItems>
    </Expand>
</Type>

If you have the Qt5.natvis file that comes with the now deprecated VS Addin, I added it to my solution so I could modify it. There were a number of things that didn't work quite right, and I've been adding plenty more types as I go.

Note: I added a view to display the string without quotes, and added the ability to use view(simple) elsewhere to suppress the children, but I think this is otherwise unmodified.

If you're still having trouble, you can turn on warning or verbose logging for Natvis:

Options > Debugging > Output Window

Upvotes: 3

Related Questions