[SOLVED] Q_ASSERT doesn’t crash an application in debug run
-
Qt 4.7.4
Qt Creator 2.2.1I 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.
-
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...:)
-
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.
-
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.
-
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?
-
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.
-
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?
-
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();
}
@
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)
@ -
Ah, I see. Gotcha.