- Qt Creator Manual
- Evaluating Expressions
- Qt Creator Manual 10.0.0-rc1

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. To insert a new expression evaluator, either double-click on an empty part of the Expressions or Locals view, or select Add New Expression Evaluator from the context menu, or drag and drop an expression from the code editor.

Note: Expression evaluators are powerful, but slow down debugger operation significantly. It is advisable to not use them excessively, and to remove unneeded expression evaluators as soon as possible.

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

The QML debugger can evaluate JavaScript 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. Most notably, inlined functions such as most `operator[]` implementations of standard containers are typically not available.

When using GDB or LLDB as backend, a special ranged syntax can be used 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]`.

Compound variables of struct or class type are displayed as expandable in the view. Expand entries to show all members. Together with the display of 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 view 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.

Note: The set of evaluated expressions is saved in your session.

## Inspecting Basic Qt Objects

The most powerful feature of the debugger is that the Locals and Expressions views show the data that belongs to Qt's basic objects. For example, in case of QObject, instead of a pointer to some private data structure, you see a list of children, signals, and slots.

Similarly, instead of displaying many pointers and integers, Qt Creator's debugger displays the contents of a QHash or QMap in an orderly manner. Also, the debugger shows access data for QFileInfo and the real contents of QVariant.

Right-click in the Locals or the Expressions view to open a context menu that has more options for viewing data. The available options depend on the type of the current items, and come from the Debugging Helpers. Typically, string-like data, such as `QByteArray` and `std::string`, offer a selection of encodings, as well as the possibility to use a full editor window. Map-like data, such as `QMap`, `QHash`, and `std::map`, offer a compact option using the `name` column for keys, resulting in a concise display of containers with short keys, such as numbers or short strings. For example, to expand all the values of QMap, select Change Value Display Format > Compact.

You can use the Locals and Expressions view to change the contents of variables of simple data types, for example, `int`, `float`, `QString` and `std::string` when the program is interrupted. To do so, click the Value column, modify the value with the inplace editor, and press Enter (or Return).

To change the complete contents of QVector or `std::vector` values, type all values separated by commas into the Value column of the main entry.

You can enable tooltips in the main editor displaying this information. For more information, see See the value of variables in tooltips while debugging.

Local Variables and Function Parameters ◦ Viewing and Editing Register State