- Qt Creator Documentation
- Evaluating Expressions
- Qt Creator 14.0.1

Reference

# 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:

- Add and remove expression evaluators
- Change value display format
- Expand and collapse view contents
- Copy view contents or expression values to the clipboard
- Open view contents in an editor
- Open memory editor
- Set data breakpoints
- Use debugging helpers
- Show and hide tooltips in the view when debugging
- Dereference pointers automatically
- Sort members of classes and structs alphabetically
- Use dynamic object type for display
- Set debugger preferences

## 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.

See also How To: Debug, Debugging, Debuggers, and Debugger.

Reference