Unsolved Debugging an application in QtCreator
-
Hello,
my application crashes and I can not find the reason why. There is a lot of signals/slots and I can not identify where the problem occurs.
I tried to debug my application using GDB. Unfortunately the only useful output I got was this:
ASSERT failure in QList<T>::operator[]: "index out of range", file C:/Qt/5.9.1/mingw53_32/include/QtCore/qlist.h, line 549
I can see I'm calling a list with wrong index. But still didn't help me. I spent many hours trying to find where the incorrect call comes from without any success.
Is there any way to trace back the call to find out at which line of my code the crash happens? Thank you.
-
Check out the Debugging section of the QtCreator manual. Debugging in QtCreator should show you where in your code you have this error (it's probably also possible with just gdb and compiled with the proper compiler flags, but I'm not as familiar with it).
-
Hi @vlada
you can get a gdb backtrace with the command
bt
. You will see a list of numbered stack frames. You can change to a specific frame with thef
command (e.g.f 23
changes to frame 23). There you can print the code with thel
and values of variables with thep <variable name>
command.You see, as soon as you make it work, it's far easier with a GUI debugger like Qt Creator than GDB.
-Michael.
-
Hi Michael, this is exactly what I'm looking for. Can I run these commands from QtCreator? Or is it somewhere directly implemented in the GUI and I just don't see it?
-
Hi use CDB debugger it available in
https://developer.microsoft.com/en-us/windows/hardware/windows-driver-kit
install and in the code in debugger mode.It will list all Error and warnings where exactly it causing problem -
@Seenu He is using MinGW, so he cannot use CDB.
-
Hi @vlada
If we run in debug mode, when there is a crash, a pointer is showed in tabular column level-function-file-line number.
According to you if pointer points at Qlist<T > - line 549,
Memory is not accessible for QList, Check list creation.go downward to get exact location.
I hope this should help you.!! -
@vlada ,
You can use backtrace command and print the variables
-
@yuvaram Hi, I think you've got a little misled here.
Debugger points you to QList source file, since it's where actual wrong index has been used by the source of it is probably in your code. Index you provided is out of bounds. I would advise putting a breakpoint in your code and then executing subroutine that fails step by step (without getting into build-in routines) to actually see which call fails. -
@artwaw
Hi ,
I agree with you. I gave sample to check logs and trace based on debug output. -
Thank you all for the useful information. Unfortunately I still don't understand the steps to get the location in my code where the QList with incorrect index was called.
Setting brake points didn't help me. I have a lot functions called by signals emitted by Qt which I can not disable. And I had hard time finding the function which caused the incorrect call. For this particular problem I already found it in the end. I have put some console output to each function end and start to know in which it crashes. Then I found the function and root cause of the problem.
But I would like to know the right and quicker solution using DBG in QtCreator.
-
debugging can be analyzed without sharing your code.