Visual Studio 2015 shows no Qstring content during debug/debugging

Asked

Viewed 49 times

1

I’m using Visual Studio 2015 to develop an application in Qt 5. Everything works correctly, but when I try to debug the code and inspect a variable of type QString, debug does not show the contents (text) of the variable, but rather internal information of the object allocation (both in the tooltip when I move the mouse over the variable, as in the Watch):

inserir a descrição da imagem aqui

Is there any way to make VS display the textual content of the variable, such as it does with ANSI and STL strings?

  • 1

    I program in Lazarus, and in it we have a debug not very efficient, but when a variable shows an address, as in your case, we use the operated to show the content of the address. In your case, it seems that VS has ways of handling this: http://stackoverflow.com/questions/22324166/visual-studio-2012-and-qt4-8-5-how-to-see-qstring-contents-in-debug-mode

  • Yes, true. I was actually answering my own question. It only took me a while because the system didn’t let me post the content I had originally prepared (I was complaining that it was too big... damn... rs). But still, thanks for your help. :)

  • What khda heim? I spent a lot of time responding, and it’s duplicated (I had already put this content here. rs). Sorry guys. I chose not to remove because here is information about upgrading to Qt version 5.7.

1 answer

0


Visual Studio has a feature called Customized Visualization of Native Objects (a free translation of the English original Custom Views of Native Objects). In the blog of Microsoft has a very nice example.

The natvis file should be added to the project, for particular use, or the folder C:\Program Files (x86)\Microsoft Visual Studio 14.0\Common7\Packages\Debugger\Visualizers for general use.

Until some time there was the Qty Visual Studio Add-in, that when installed provided a number of facilities for using Qt in VS, including a natvis file. This add-in is now obsolete (deprecated) but you can use your file qt5.natvis (found in some internet repositories, such as that). Part of the file is played below, but download it from the original source (it is too big to fit all here):

<?xml version="1.0" encoding="utf-8"?>
<AutoVisualizer xmlns="http://schemas.microsoft.com/vstudio/debugger/natvis/2010">
    <Type Name="QPoint">
        <AlternativeType Name="QPointF"/>
        <DisplayString>{{ x = {xp}, y = {yp} }}</DisplayString>
        <Expand>
            <Item Name="[x]">xp</Item>
            <Item Name="[y]">yp</Item>
        </Expand>
    </Type>
    <Type Name="QRect">
        <DisplayString>{{ x = {x1}, y = {y1}, width = {x2 - x1 + 1}, height = {y2 - y1 + 1} }}</DisplayString>
        <Expand>
            <Item Name="[x]">x1</Item>
            <Item Name="[y]">y1</Item>
            <Item Name="[width]">x2 - x1 + 1</Item>
            <Item Name="[height]">y2 - y1 + 1</Item>
        </Expand>
    </Type>
    <Type Name="QRectF">
        <DisplayString>{{ x = {xp}, y = {yp}, width = {w}, height = {h} }}</DisplayString>
        <Expand>
            <Item Name="[x]">xp</Item>
            <Item Name="[y]">yp</Item>
            <Item Name="[width]">w</Item>
            <Item Name="[height]">h</Item>
        </Expand>
    </Type>
    <Type Name="QSize">
        <AlternativeType Name="QSizeF"/>
        <DisplayString>{{ width = {wd}, height = {ht} }}</DisplayString>
        <Expand>
            <Item Name="[width]">wd</Item>
            <Item Name="[height]">ht</Item>
        </Expand>
    </Type>
    <Type Name="QLine">
        <AlternativeType Name="QLineF"/>
        <DisplayString>{{ start point = {pt1}, end point = {pt2} }}</DisplayString>
        <Expand>
            <Synthetic Name="[start point]">
                <DisplayString>{pt1}</DisplayString>
                <Expand>
                    <ExpandedItem>pt1</ExpandedItem>
                </Expand>
            </Synthetic>
            <Synthetic Name="[end point]">
                <DisplayString>{pt2}</DisplayString>
                <Expand>
                    <ExpandedItem>pt2</ExpandedItem>
                </Expand>
            </Synthetic>
        </Expand>
    </Type>

    . . .

    <Type Name="QChar">
        <DisplayString>{ucs,c}</DisplayString>
        <StringView>ucs,c</StringView>
        <Expand>
            <Item Name="[latin 1]">ucs > 0xff ? '\0' : char(ucs),c</Item>
            <Item Name="[unicode]">ucs,c</Item>
        </Expand>
    </Type>
    <Type Name="QString">
        <DisplayString>{d-&gt;data,sub}</DisplayString>
        <StringView>d-&gt;data,sub</StringView>
        <Expand>
            <Item Name="[size]">d-&gt;size</Item>
            <Item Name="[referenced]">d-&gt;ref._q_value</Item>
            <ArrayItems>
                <Size>d-&gt;size</Size>
                <ValuePointer>(d->data),c</ValuePointer>
            </ArrayItems>
        </Expand>
    </Type>
    <Type Name="QT::QString">
        <DisplayString>{d-&gt;data,sub}</DisplayString>
        <StringView>d-&gt;data,sub</StringView>
        <Expand>
            <Item Name="[size]">d-&gt;size</Item>
            <Item Name="[referenced]">d-&gt;ref._q_value</Item>
            <ArrayItems>
                <Size>d-&gt;size</Size>
                <ValuePointer>(d->data),c</ValuePointer>
            </ArrayItems>
        </Expand>
    </Type>

    . . .

</AutoVisualizer>

The visualization of QString of that file does not work in Qt version 5.7, but there is an update that can be overwritten (the source is from the OS):

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

After saving the natvis file in the viewer directory and restarting the VS, you have an appropriate view of QString:

inserir a descrição da imagem aqui

Browser other questions tagged

You are not signed in. Login or sign up in order to post.