- Extending Qt Creator Manual
- QtCreator
- ActionBuilder
- Extending Qt Creator Manual 20.0.0-rc1

# Core::ActionBuilder Class

class Core::ActionBuilder

The ActionBuilder class is convienience class to set up Core::Commands. More...

Header: | `#include <coreplugin/actionmanager/actionmanager.h>`

- List of all members, including inherited members

## Public Functions

| ActionBuilder(QObject *contextActionParent, const Utils::Id actionId)
| ~ActionBuilder()
Core::ActionBuilder & | adopt(Utils::Action *action)
Core::ActionBuilder & | setIconText(const QString &iconText)
Core::ActionBuilder & | setText(const QString &text)

## Detailed Description

An action builder specifies properties of a `Core::Command` and a context action and uses ActionManager::registerAction() in its destructor to actually register the action for a set Core::Context for the Command.

## Member Function Documentation

### ActionBuilder::ActionBuilder(QObject *contextActionParent, const Utils::Id actionId)

Constructs an action builder for an action with the Id actionId.

The contextActionParent is used to provide a QObject parent for the internally constructed QAction object to control its life time.

This is typically the `this` pointer of the entity using `ActionBuilder`.

### `[noexcept]` ActionBuilder::~ActionBuilder()

Registers the created action with the set properties.

See also ActionManager::registerAction().

### Core::ActionBuilder &ActionBuilder::adopt(Utils::Action *action)

Uses the given action is the contextAction for this builder. action must not be nullptr, and adopt() must be called before setting any actual properties like setText() or setIcon().

Usually you should prefer passing a `contextActionParent` to the ActionBuilder constructor, and binding a QAction to the automatically created context action with bindContextAction().

This method is sometimes useful if the caller manages the action's lifetime itself, and for example there is no QObject that can be the parent of an automatically created context action.

### Core::ActionBuilder &ActionBuilder::setIconText(const QString &iconText)

Sets the `iconText` property of the action under construction to iconText.

See also QAction::setIconText().

### Core::ActionBuilder &ActionBuilder::setText(const QString &text)

Sets the `text` property of the action under construction to text.

See also QAction::setText().