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

7

21

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

Deontology answered 11/3, 2014 at 11:19 Comment(0)
B
27

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
Besmirch answered 18/5, 2016 at 8:16 Comment(2)
getting: -var-create: unable to create variable objectRushing
thank you, option for Qt5((char*)str.d + str.d->offset,su) helped me)Schreiner
E
8

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

Elconin answered 28/5, 2014 at 15:41 Comment(2)
Great ! the debugger options set to "Enable native Edit and Continue" and the natvis file work ! Thank.Deontology
VS2015 the autoexp.dat ist still a INI like file .... No XML at all there ... What I am missing?Rushing
B
6


For Visual 2015, 2017 and 2019,
just install the dedicated Qt plugin for Visual.
Download it from here

Bruin answered 3/6, 2020 at 14:49 Comment(0)
S
3

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.

Sorce answered 22/6, 2014 at 20:17 Comment(1)
Hi, It is not in the project's properties. Go to Tools menu -> options -> debugging -> Edit and Continue. Check Native Edit and continue.Deontology
M
1

For Visual Studio 2015...

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

Metritis answered 10/7, 2017 at 12:32 Comment(0)
S
0

For me, this worked for QString qStr :

p qStr.toStdString();

I executed this in command line (available in visual studio), worked in gdb and lldb.

Sokol answered 13/2, 2023 at 11:20 Comment(0)
S
0

For Visual Studio 2013, I found the following extension still works to display QStrings, even though it is no longer officially supported: https://marketplace.visualstudio.com/items?itemName=TheQtCompany.QtVisualStudioTools

Not sure if there is an equivalent for VS 2012; I found this in an old email from when we had just adopted VS 2013, but I've just verified that it still works for VS 2013 and Qt 5.5.1.

Stoa answered 18/6 at 1:58 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.