Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Qt Creator and other tools
  4. [SOLVED] Q_ASSERT doesn’t crash an application in debug run
Forum Updated to NodeBB v4.3 + New Features

[SOLVED] Q_ASSERT doesn’t crash an application in debug run

Scheduled Pinned Locked Moved Qt Creator and other tools
9 Posts 3 Posters 11.1k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • H Offline
    H Offline
    Hostel
    wrote on last edited by
    #1

    Qt 4.7.4
    Qt Creator 2.2.1

    I have a problem probably with Qt Creator. Today I found that Q_ASSERT doesn't work correctly on my Linux. In the past everything worked good. I tested Q_ASSERT like this:
    @
    Q_ASSERT( false );
    @
    This code crashes my app in Qt Creator only if I run by Run(Ctrl+R), but when I hit a Debug Run(F5) then Qt Creator jumps to Q_ASSERT line like to a breakpoint and doesn't crash my application.

    On Windows I have similar Qt and Qt Creator, but there Q_ASSERT crash application in Run and Debug Run. I think that something is wrong with Qt Creator settings, but I don't know what.

    On Windows and Linux I compiled program in debug mode.

    Sorry for my english.

    1 Reply Last reply
    0
    • S Offline
      S Offline
      shoyeb
      wrote on last edited by
      #2

      basically the thing is that when u compile ur code in the debug mode then compiler will compile ur entire code including the asserts, but when u compile ur code in release mode the compiler will skip the assert and many other thing, basically cimpiler is not skipping them its supressing these warnings in the runtime, so when u compile ur code in release mode the ur code will not crash.

      but i prefer u to to do ur entire development in the debug mode, so thet u can handle aal the runtime errors which u may get in future, and after all coding of ur roject is done then u can release ur project using the release mode...

      so always develop in debug mode and deploy in release mode...:)

      There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code.

      1 Reply Last reply
      0
      • H Offline
        H Offline
        Hostel
        wrote on last edited by
        #3

        My code is compiled in debug mode, and Q_ASSERT doesn't crash application - Q_ASSERT is in code, I can set breakpoint on it. In release mode Q_ASSERT is absent and this is right. I discovered this problem, when I compiled an application on Windows.

        1 Reply Last reply
        0
        • H Offline
          H Offline
          Hostel
          wrote on last edited by
          #4

          qFatal also do not abort application when I'm debugging in Qt Creator. If I run application without debugging then qFatal print a message and abort application.

          1 Reply Last reply
          0
          • M Offline
            M Offline
            mlong
            wrote on last edited by
            #5

            When you're running an app in a debugger and the application ends abnormally (a crash, or an abort, or a failed assertion, or whatever) the debugger "catches" the application at the point where the program terminated. That's the way a debugger is supposed to work. Or am I missing something else that you're expecting to happen?

            Software Engineer
            My views and opinions do not necessarily reflect those of anyone -- living or dead, real or fictional -- in this universe or any other similar multiverse node. Void where prohibited. Your mileage may vary. Caveat emptor.

            1 Reply Last reply
            0
            • H Offline
              H Offline
              Hostel
              wrote on last edited by
              #6

              I resolved a problem by downloading a Qt Creator 2.4.1. In this version debugging works fine.

              @mlong - in Qt Creator 2.2.1 qFatal crash application, when I run app outside Qt Creator. When I was debugging in Qt Creator then qFatal doesn't crash app.

              1 Reply Last reply
              0
              • M Offline
                M Offline
                mlong
                wrote on last edited by
                #7

                I'm still not sure what you meant by it doesn't crash the app. In the debugger, it should act like a breakpoint was set and return you to the place where the assert was failing. Is that not what was happening?

                Software Engineer
                My views and opinions do not necessarily reflect those of anyone -- living or dead, real or fictional -- in this universe or any other similar multiverse node. Void where prohibited. Your mileage may vary. Caveat emptor.

                1 Reply Last reply
                0
                • H Offline
                  H Offline
                  Hostel
                  wrote on last edited by
                  #8

                  Example:
                  @
                  #include <QtCore/QCoreApplication>

                  #include <QDebug>

                  int main(int argc, char *argv[])
                  {
                  QCoreApplication a(argc, argv);

                  Q_ASSERT( false );
                  
                  qDebug() << "I'm alive!";
                  
                  return a.exec&#40;&#41;;
                  

                  }
                  @
                  Debug build. Then start debugging(F5) - output:
                  @
                  I'm alive!
                  @

                  Start in Qt Creator by run(Ctrl+R) - output:
                  @
                  ASSERT: "false" in file ../assert_issue/main.cpp, line 9
                  The program has unexpectedly finished.
                  @

                  Start outside Qt Creator - output:
                  @
                  ASSERT: "false" in file ../assert_issue/main.cpp, line 9
                  Przerwane (core dumped)
                  @

                  1 Reply Last reply
                  0
                  • M Offline
                    M Offline
                    mlong
                    wrote on last edited by
                    #9

                    Ah, I see. Gotcha.

                    Software Engineer
                    My views and opinions do not necessarily reflect those of anyone -- living or dead, real or fictional -- in this universe or any other similar multiverse node. Void where prohibited. Your mileage may vary. Caveat emptor.

                    1 Reply Last reply
                    0

                    • Login

                    • Login or register to search.
                    • First post
                      Last post
                    0
                    • Categories
                    • Recent
                    • Tags
                    • Popular
                    • Users
                    • Groups
                    • Search
                    • Get Qt Extensions
                    • Unsolved