WATCH Macros

API: WATCH Macros
API
WATCH Macros
#define WATCH(variable)
 Makes variables inspectable in Qtenv. String representation is produced using str() for cObject descendants, and the stream write operator (operator<<) for other types. For compound types, fields are queried using the associated class descriptor of the type (see cClassDescriptor).
#define WATCH_EXPR(name, expression)
 Makes the result of a formula or calculation inspectable in Qtenv without requiring a separate variable. The expression is evaluated as often as needed, providing real-time monitoring of derived metrics. Unlike WATCH which monitors single variables, WATCH_EXPR can display the result of operations combining multiple variables, function calls, or any valid expression.
#define WATCH_LAMBDA(name, lambdaFunction)
 Makes the result of a lambda function inspectable in Qtenv. This is a more flexible (but also more verbose) version of WATCH_EXPR().

Description

WATCH macros make normal variables show up in Qtenv inspectors.

Macro Definition Documentation

◆ WATCH

#define WATCH ( variable)

Makes variables inspectable in Qtenv. String representation is produced using str() for cObject descendants, and the stream write operator (operator<<) for other types. For compound types, fields are queried using the associated class descriptor of the type (see cClassDescriptor).

◆ WATCH_EXPR

#define WATCH_EXPR ( name,
expression )

Makes the result of a formula or calculation inspectable in Qtenv without requiring a separate variable. The expression is evaluated as often as needed, providing real-time monitoring of derived metrics. Unlike WATCH which monitors single variables, WATCH_EXPR can display the result of operations combining multiple variables, function calls, or any valid expression.

The macro works by creating a lambda that captures this, so only member variables and member functions of the enclosing class can be used in the expression. To use local variables, use WATCH_LAMBDA() with an explicit capture list instead.

Example: WATCH_EXPR("totalPks", numTransmitted + queue.length() + numDropped)

◆ WATCH_LAMBDA

#define WATCH_LAMBDA ( name,
lambdaFunction )

Makes the result of a lambda function inspectable in Qtenv. This is a more flexible (but also more verbose) version of WATCH_EXPR().

Unlike WATCH_EXPR which only captures this, WATCH_LAMBDA allows you to specify an arbitrary capture list. Local variables may be captured by value or by reference; however, note that the watch object typically outlives the local scope, so capturing locals by reference may result in dangling references.

Example: WATCH_LAMBDA("totalPks", [this]() { return numTransmitted + queue.length() + numDropped; })