Qt 6.x
The Qt SDK
Loading...
Searching...
No Matches
qssgassert.cpp File Reference
#include "qssgassert_p.h"
+ Include dependency graph for qssgassert.cpp:

Go to the source code of this file.

Functions

QT_BEGIN_NAMESPACE void qssgWriteAssertLocation (const char *msg)
 Collection of assert checks that causes a soft or hard assert depending on the build.
 

Function Documentation

◆ qssgWriteAssertLocation()

QT_BEGIN_NAMESPACE void qssgWriteAssertLocation ( const char *  msg)

Collection of assert checks that causes a soft or hard assert depending on the build.

Unlike Q_ASSERT(), which is a no-op for non-debug build, QSSG_ASSERT() etc., will print a warning in non-developer builds (soft assert) or terminate on developer-build (hard assert).

\macro QSSG_ASSERT(condition, action)

The assert will be fatal in developer builds if condition is not met. In non-developer builds the assert is "soft" and will instead print a warning with the reason and location of the assert before execution action. The action can be for example be: return, break or continue.

For example, writing:

\badcode QSSG_ASSERT(ptr != nullptr, return);

other actions are of course possible, e.g., in a loop it might be better to do:

\badcode QSSG_ASSERT(ptr != nullptr, continue);

is the equivalent to:

\badcode Q_ASSERT(ptr != nullptr); if (ptr != nullptr) { qWarning() << "Something unexpected here, proceeding will be fatal!"; return; }

See also
QSSG_ASSERT_X

\macro QSSG_ASSERT_X(condition, message, action)

Same as \l QSSG_ASSERT() but with a custom message that will be print if condition is not met.

\macro QSSG_CHECK(condition)

Similar to \l QSSG_ASSERT but without an action. Convenient when the condition is expected to be valid, but it's not immediately fatal if the current code path continues.

\badcode QSSG_CHECK(ptr != nullptr);

is the equivalent to:

\badcode Q_ASSERT(ptr != nullptr); if (ptr != nullptr) qWarning() << "Something unexpected here, will probably not work as expected!";

See also
QSSG_CHECK_X

\macro QSSG_CHECK_X(condition, message)

Same as \l QSSG_CHECK() but with a custom message that will be print if condition is not met.

\macro QSSG_GUARD(condition)

Check that returns the result of condition. As with the other assert functions, a call to QSSG_GUARD, when condition is not met, is fatal for developer builds.

\badcode

if (QSSG_GUARD(ptr != nullptr)) { ... // OK } else { ... // We shouldn't be here! }

is the equivalent to:

\badcode if (ptr != nullptr) { ... // OK } else { Q_ASSERT(ptr != nullptr); qWarning() << "Something unexpected here!"; }

See also
QSSG_GUARD_X

\macro QSSG_GUARD_X(condition, message)

Same as \l QSSG_GUARD() but with a custom message that will be print if condition is not met.

Definition at line 119 of file qssgassert.cpp.

References qFatal, and qWarning.