PDA

View Full Version : Q_assert



ggdev001
1st March 2013, 08:16
Hello,
I tried using Q_ASSERT macro at several places and it seems not always it produces the output if the condition if false.

Where to check for its output if the condition if false????

The condition check worked, I got some No Source found for SignalKill or smth. But I could not
find the output of Q_ASSERT (whereas I was able to do it in some other cases).

ps. And how would you check for valid pointers using Q_ASSERT?

pps. Btw. would such a check be oK? Q_ASSERT(pointer1 && pointer2 && pointer3)
if I want to check multiple pointers.

Thanks.

wysota
1st March 2013, 11:06
Q_ASSERT works only in debug mode. It doesn't provide output, it kills your app with a message that the assertion has failed.


pps. Btw. would such a check be oK? Q_ASSERT(pointer1 && pointer2 && pointer3)
if I want to check multiple pointers.
Using three Q_CHECK_PTR calls would be cleaner. An assert with three pointers doesn't tell you which of them were null so from debugging point of view such assertion is rather useless.

ggdev001
1st March 2013, 11:37
Q_ASSERT works only in debug mode. It doesn't provide output, it kills your app with a message that the assertion has failed.


Using three Q_CHECK_PTR calls would be cleaner. An assert with three pointers doesn't tell you which of them were null so from debugging point of view such assertion is rather useless.
Yes, it killed my app that's true. But the doc says: "Prints a warning message containing the source code file name and line number if test is false."
http://qt-project.org/doc/qt-4.8/qtglobal.html#Q_ASSERT
The thing is it killed my app but I could not find that warning message mentioned above... ??? (it did once though with other Q_ASSERT). Where to look for it? Thanks.

wysota
1st March 2013, 12:14
The thing is it killed my app but I could not find that warning message mentioned above... ???
Maybe it's not an assertion that killed your app.


#include <QtGlobal>

int main() {
Q_ASSERT(false);
return 0;
}

ASSERT: "false" in file main.cpp, line 4