Results 1 to 4 of 4

Thread: How to break in debugger in Q_ASSERT ?

  1. #1
    Join Date
    Jun 2008
    Posts
    57
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default How to break in debugger in Q_ASSERT ?

    Hello!
    I' m using Qt 4.6 + QtCreator + MinGW.
    When an expression in Q_ASSERT evaluates to false my application just aborts with a message in the debug output, that is often meaningless. How can I make it to break into debugger to the line that contains the assert, so I can see the call stack?
    I googled a lot, but found only
    asm("int $0x3");
    which is weird and won't work in x64.
    Thanks in advance.

  2. #2
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: How to break in debugger in Q_ASSERT ?

    Quote Originally Posted by Radagast View Post
    When an expression in Q_ASSERT evaluates to false my application just aborts with a message in the debug output, that is often meaningless
    That's exactely like assert should work. And I can't say that the message is meaningless. It says in with line and in wich file the "error" occurs and then you can have a look at your statement and see why assert was triggered. If that is not enough you can have a look at Q_ASSERT_X to pass an option string which explains the error more. If you want to go in your debugger you can do that as an workaround:
    Qt Code:
    1. if (condition)
    2. {
    3. // <- set your break point here.
    4. }
    To copy to clipboard, switch view to plain text mode 

  3. #3
    Join Date
    Jun 2008
    Posts
    57
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: How to break in debugger in Q_ASSERT ?

    In MS Visual Studio I break in debugger on assertions, which is much more useful than what we have in Qt Creator.
    And if Q_ASSERT fails not in my code, but in Qt, the info about line and file is useless.

  4. #4
    Join Date
    Sep 2009
    Location
    UK
    Posts
    2,447
    Thanks
    6
    Thanked 348 Times in 333 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: How to break in debugger in Q_ASSERT ?

    On windows, you can write your own ASSERT-style macro to call DebugBreak() which is like INT 3 but works across all supported CPUs.

    (INT 3 simply means "Breakpoint Interrupt". People use it because it is fast and easy to type whilst writing code. It's easier than typing non-sense code, or hoping the compiler doesn't optimise it out, and coping with the breakpoints becoming invalid or moving as you edit the code)

Similar Threads

  1. How to add page break when printe a webview to PDF format
    By richardander in forum Qt Programming
    Replies: 1
    Last Post: 18th December 2009, 15:21
  2. QT IDE and Debugger
    By onefootswill in forum Newbie
    Replies: 16
    Last Post: 25th July 2008, 20:39
  3. font incorrectly show - font break.
    By sgh in forum Qt Programming
    Replies: 9
    Last Post: 30th May 2008, 02:35
  4. break a file
    By mickey in forum General Programming
    Replies: 5
    Last Post: 24th February 2008, 12:17
  5. Need Qt IDE with Debugger
    By rajeshs in forum General Discussion
    Replies: 3
    Last Post: 10th October 2007, 12:21

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.