开发者

Debugging asserts in Qt Creator

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 stac开发者_JS百科k 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?


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"


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.


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜