Debugging asserts in Qt Creator
Solution 1
You can install a handler for the messages/warnings that Qt emits, and do your own processing of them. See the documentation for qInstallMsgHandler
and the example they give there. It should be easy to insert a break in a custom message handler (or indeed, just assert on your own at that point). The one small drawback is that you'll be a bit further on down the stack than where the error actually occurred, but it is a simple matter to just step up the stack until you are at the proper frame.
Solution 2
It's possible. Somehow the feature stopped working for me, but basically what you want is to stop on qFatal(). To ensure this happens, in qt Creator go to Tools -> Options -> Debugger -> GDB and select "Stop when a qFatal is issued"
Solution 3
It's possible. I have coded a BreakInDebugger function by hand and an assert macro that calls the function.
e.g: #define MyAssert(X) (BreakInDebugger();Q_ASSERT(X))
![nog642](https://lh3.googleusercontent.com/-b1a7rR39Ekk/AAAAAAAAAAI/AAAAAAAAA94/GY5zFlngiyA/photo.jpg?sz=256)
Comments
-
nog642 about 2 years
When I hit a normal assert statement while debugging with Visual Studio I get the option to break into the debugger so I can see the entire stack trace and the local variables, not just the assert message.
Is it possible to do this with Qt Creator+mingw32 and Q_ASSERT/Q_ASSERT_X?
-
nog642 over 14 yearsI used the example with __asm("int3") before the abort() call and it works great.
-
Peter Tseng almost 10 yearsLooks like the right option (why is it not on by default?), but it doesn't seem to work for me either.
-
Paulo Carvalho almost 7 yearsThe configuration pane is called "GDB Extended" in Qt Creator 5.3 and possibly later.
-
Paulo Carvalho almost 7 yearsWorked for me: Qt Creator 5.3 (32) + Qt Libraries 5.9 (64) + MSYS2/MinGW (64).
-
nurdglaw almost 4 yearsWorks for me too, QtCreator 5.12.4 except that the checkbox has moved to the "GDB Extended" tab. This answer is MUCH better than the accepted one.