- Qt Creator Manual
- Developing with Qt Creator
- Debugging
- Debug Mode Views
- Evaluating Expressions
- Qt Creator Manual 13.0.0

Local Variables and Function Parameters ◦ Viewing and Editing Register State

# Evaluating Expressions

To compute values of arithmetic expressions or function calls, use expression evaluators in the Expressions view.

You can examine static variables that the debuggers don't pick up as local variables. For example, if you define `static int staticVar = 42;` in a source file and then add `staticVar` as an evaluated expression, you should see 42 in the view when the debugger stops in the source file.

## Adding Expression Evaluators

To add expression evaluators, drag an expression from the code editor to the Expressions view.

You can also:

- Double-click in the Expressions or Locals view.
- Select Add New Expression Evaluator from the context menu.

Enter the expression in the New Evaluated Expression dialog:

The set of evaluated expressions is saved in your session.

Note: Expression evaluators are powerful, but slow down debugger operation significantly. Use them sparingly and remove them when you no longer need them.

Expression evaluators are re-evaluated whenever the current frame changes. The functions used in the expressions are called each time, even if they have side-effects.

## Expressions View Actions

Right-click the Expressions view to select the following actions:

## JavaScript Expressions

The QML debugger can evaluate JavaScript expressions.

## C and C++ Expressions

GDB, LLDB and CDB support the evaluation of simple C and C++ expressions. Functions can be called only if they are actually compiled into the debugged executable or a library used by the executable. Inlined functions such as most `operator[]` implementations of standard containers are typically not available.

When using GDB or LLDB as backend, you can use a special ranged syntax to display multiple values with one expression. A sub-expression of form `foo[a..b]` is split into a sequence of individually evaluated expressions `foo[a], ..., foo[b]`.

You can expand compound variables of struct or class type to show their members. As you also see the variable value and type, you can examine and traverse the low-level layout of object data.

GDB and LLDB, and therefore Qt Creator's debugger, also work for optimized builds on Linux and macOS. Optimization can lead to re-ordering of instructions or removal of some local variables, causing the Locals and Expressions views to show unexpected data.

The debug information from GCC does not include enough information about the time when a variable is initialized. Therefore, Qt Creator can not tell whether the contents of a local variable are real data or initial noise. If a QObject appears uninitialized, its value is reported as not in scope. Not all uninitialized objects, however, can be recognized as such.