PDA

View Full Version : How to View QString Object data while debugging?



payal
24th February 2010, 07:05
Hi,

While debugging its not possible to view the QString object data in Locals & Watchers in QtCreator.Its showing blank.Only int and addresses are shown under the Value section.

Plz any one share ur ideas if u know?


Regards,
Payal

BalaQT
24th February 2010, 07:16
hi payal
u can use qDebug() to know the values at runtime

ex



QString str="welcome";
qDebug()<<str;


see the result in Application Output [alt+3]
hope it helps
Bala

payal
24th February 2010, 07:27
i tried using as per your code,i am getting following errors.

1.error: invalid use of incomplete type ‘struct QDebug’
2./usr/include/qt4/QtCore/qglobal.h:1467: error: forward declaration of ‘struct QDebug’

Any idea how to resolve this?

BalaQT
24th February 2010, 07:38
hi,
have u included <QtGui> ?

if QtGui included then QDebug will work

if not include <QDebug>

hope it helps
Bala

payal
24th February 2010, 07:56
Thanks alot,it got solved by including <QtGui>

I was tring with <qDebug>

BalaQT
24th February 2010, 08:00
It will work with <QDebug> not <qDebug>

anyway , if u include <QtGui> there is no need to include <QDebug>

Bala

JJones
15th February 2011, 06:34
View QT Objects While Debugging
See your QStrings without drilling down!

(quick view in bold)

The kde-devel-gdb package has a bunch of gdb command definitions to help with viewing QString as well as other structures in gdb. You can also use this from within Eclipse via the gdb terminal.

First of all, you need to get the commands loaded into gdb.

get the gdb commands file ( I'll paste the current version on the end here) from kde-devel-gdb.
modify your ~/.gdbinit file to reference it by adding this line at the end:
source ~/kde-devel-gdb

now run gdb in a terminal and type:
apropos q4
and you should see a number of the new commands appear ( such as printq4string )
use the 'q' command to quit

Now run Eclipse

Within Eclipse, go to the Run->DebugConfigurations... Debugger tab and set the GDB command file to your .gdbinit . It may look right... browse to and choose it again anyways.

start debugging something and get to a breakpoint preferably near a QString.

Note that if you select the gdb process in the debug window that the console will switch to gdb.
That changes the context however and you can't get to your variables.

instead, select a thread in the debug window that gets you back to your variable list and then on the upper right of the console window select the little computer monitor drop down and choose gdb.

try apropos q4 again in this gdb console... verify that the printq4string command is there. If not then see the line above just after 'Run Eclipse'. You can also manually run 'source ~/kde-devel-gdb'

now, in the gdb console try to get a QString to print..
printq4string your_QString_here

success!


problems still?:
my gdbinit's 3rd line wasn't liked by gdb and I had to comment it out. watch for complaints when you run gdb from a terminal.
note.. it's printq4string NOT printqt4string.. no 'T'! I'm changing mine to pq or something short instead anyways.

If you figure out a way to automate this further in the eclipse debugger ( use a gdb command in a watch?? debug view casting? ) please tell the rest of us!
(I'm at least changing to a shortened command name.. )

5950
I'll attach the kde-devel-gdb file from: http://websvn.kde.org/trunk/KDE/kdesdk/scripts/kde-devel-gdb . Fewb 14, 2011 version.