MessageBoxHandler Class | Qt Installer Framework Manual

- Qt Installer Framework Manual
- MessageBoxHandler

# MessageBoxHandler Class

class QInstaller::MessageBoxHandler

The MessageBoxHandler class provides a modal dialog for informing the user or asking the user a question and receiving an answer. More...

Header: | #include <MessageBoxHandler>

- List of all members, including inherited members

## Public Types

enum | DefaultAction { AskUser, Accept, Reject, Default }
enum | MessageType { criticalType, informationType, questionType, warningType }

## Public Functions

int | critical(const QString &identifier, const QString &title, const QString &text, int buttons = QMessageBox::Ok, int button = QMessageBox::NoButton)
int | information(const QString &identifier, const QString &title, const QString &text, int buttons = QMessageBox::Ok, int button = QMessageBox::NoButton)
int | question(const QString &identifier, const QString &title, const QString &text, int buttons = QMessageBox::Yes | QMessageBox::No, int button = QMessageBox::NoButton)
void | setAutomaticAnswer(const QString &identifier, QMessageBox::StandardButton answer)
void | setDefaultAction(QInstaller::MessageBoxHandler::DefaultAction defaultAction)
int | warning(const QString &identifier, const QString &title, const QString &text, int buttons = QMessageBox::Ok, int button = QMessageBox::NoButton)

## Static Public Members

QMessageBox::StandardButton | critical(QWidget *parent, const QString &identifier, const QString &title, const QString &text, QMessageBox::StandardButtons buttons = QMessageBox::Ok, QMessageBox::StandardButton button = QMessageBox::NoButton)
QWidget * | currentBestSuitParent()
QMessageBox::StandardButton | information(QWidget *parent, const QString &identifier, const QString &title, const QString &text, QMessageBox::StandardButtons buttons = QMessageBox::Ok, QMessageBox::StandardButton button = QMessageBox::NoButton)
QInstaller::MessageBoxHandler * | instance()
QList<QMessageBox::Button> | orderedButtons()
QMessageBox::StandardButton | question(QWidget *parent, const QString &identifier, const QString &title, const QString &text, QMessageBox::StandardButtons buttons = QMessageBox::Yes | QMessageBox::No, QMessageBox::StandardButton button = QMessageBox::NoButton)
QMessageBox::StandardButton | warning(QWidget *parent, const QString &identifier, const QString &title, const QString &text, QMessageBox::StandardButtons buttons = QMessageBox::Ok, QMessageBox::StandardButton button = QMessageBox::NoButton)

## Detailed Description

     var result = QMessageBox.question("quit.question", "Installer", "Do you want to quit the installer?",
                                       QMessageBox.Yes | QMessageBox.No);
     if (result == QMessageBox.Yes) {
        // ...
     }

#### Buttons in Message Boxes

`QMessageBox` defines a list of common buttons:

- OK
- Open
- Save
- Cancel
- Close
- Discard
- Apply
- Reset
- RestoreDefaults
- Help
- SaveAll
- Yes
- YesToAll
- No
- NoToAll
- Abort
- Retry
- Ignore
- NoButton

## Member Type Documentation

### enum MessageBoxHandler::DefaultAction

This enum value holds the default action for the message box handler:

Constant | Value | Description
--- | --- | ---
`QInstaller::MessageBoxHandler::AskUser` | `0` | Ask the end user for confirmation.
`QInstaller::MessageBoxHandler::Accept` | `1` | Accept the message box.
`QInstaller::MessageBoxHandler::Reject` | `2` | Reject the message box.
`QInstaller::MessageBoxHandler::Default` | `3` | Uses default answer set for message box.

### enum MessageBoxHandler::MessageType

This enum value holds the severity level of the message displayed in the message box:

Constant | Value | Description
--- | --- | ---
`QInstaller::MessageBoxHandler::criticalType` | `0` | Reports critical errors.
`QInstaller::MessageBoxHandler::informationType` | `1` | Reports information about normal operations.
`QInstaller::MessageBoxHandler::questionType` | `2` | Asks a question during normal operations.
`QInstaller::MessageBoxHandler::warningType` | `3` | Reports non-critical errors.

## Member Function Documentation

### `[static]` QMessageBox::StandardButton MessageBoxHandler::critical(QWidget *parent, const QString &identifier, const QString &title, const QString &text, QMessageBox::StandardButtons buttons = QMessageBox::Ok, QMessageBox::StandardButton button = QMessageBox::NoButton)

Opens a critical message box with the parent parent, identifier identifier, title title, and text text.

The standard buttons specified by buttons are added to the message box. button specifies the button that is used when Enter is pressed. button must refer to a button that is specified in buttons. If button is QMessageBox::NoButton, a suitable default is chosen automatically.

Returns the identity of the standard button that was clicked. However, if Esc was pressed, returns the escape button.

### `[invokable]` int MessageBoxHandler::critical(const QString &identifier, const QString &title, const QString &text, int buttons = QMessageBox::Ok, int button = QMessageBox::NoButton)

Opens a critical message box with the identifier identifier, title title, and text text.

The standard buttons specified by buttons are added to the message box. button specifies the button that is used when Enter is pressed. button must refer to a button that is specified in buttons. If button is QMessageBox::NoButton, a suitable default is chosen automatically.

Returns the identity of the standard button that was clicked. However, if Esc was pressed, returns the escape button.

Note: This function can be invoked via the meta-object system and from QML. See Q_INVOKABLE.

### `[static]` QWidget *MessageBoxHandler::currentBestSuitParent()

Returns the widget or window that is most suitable to become the parent of the message box. Returns `0` if an application cannot be found.

### `[static]` QMessageBox::StandardButton MessageBoxHandler::information(QWidget *parent, const QString &identifier, const QString &title, const QString &text, QMessageBox::StandardButtons buttons = QMessageBox::Ok, QMessageBox::StandardButton button = QMessageBox::NoButton)

Opens an information message box with the parent parent, identifier identifier, title title, and text text.

The standard buttons specified by buttons are added to the message box. button specifies the button that is used when Enter is pressed. button must refer to a button that is specified in buttons. If button is QMessageBox::NoButton, a suitable default is chosen automatically.

Returns the identity of the standard button that was clicked. However, if Esc was pressed, returns the escape button.

### `[invokable]` int MessageBoxHandler::information(const QString &identifier, const QString &title, const QString &text, int buttons = QMessageBox::Ok, int button = QMessageBox::NoButton)

Opens an information message box with the identifier identifier, title title, and text text.

The standard buttons specified by buttons are added to the message box. button specifies the button that is used when Enter is pressed. button must refer to a button that is specified in buttons. If button is QMessageBox::NoButton, a suitable default is chosen automatically.

Returns the identity of the standard button that was clicked. However, if Esc was pressed, returns the escape button.

Note: This function can be invoked via the meta-object system and from QML. See Q_INVOKABLE.

### `[static]` QInstaller::MessageBoxHandler *MessageBoxHandler::instance()

Returns a message box handler instance.

### `[static]` QList<QMessageBox::Button> MessageBoxHandler::orderedButtons()

Returns an ordered list of buttons to display in the message box.

### `[static]` QMessageBox::StandardButton MessageBoxHandler::question(QWidget *parent, const QString &identifier, const QString &title, const QString &text, QMessageBox::StandardButtons buttons = QMessageBox::Yes | QMessageBox::No, QMessageBox::StandardButton button = QMessageBox::NoButton)

Opens a question message box with the parent parent, identifier identifier, title title, and text text.

The standard buttons specified by buttons are added to the message box. button specifies the button that is used when Enter is pressed. button must refer to a button that is specified in buttons. If button is QMessageBox::NoButton, a suitable default is chosen automatically.

Returns the identity of the standard button that was clicked. However, if Esc was pressed, returns the escape button.

### `[invokable]` int MessageBoxHandler::question(const QString &identifier, const QString &title, const QString &text, int buttons = QMessageBox::Yes | QMessageBox::No, int button = QMessageBox::NoButton)

Opens a question message box with the identifier identifier, title title, and text text.

The standard buttons specified by buttons are added to the message box. button specifies the button that is used when Enter is pressed. button must refer to a button that is specified in buttons. If button is QMessageBox::NoButton, a suitable default is chosen automatically.

Returns the identity of the standard button that was clicked. However, if Esc was pressed, returns the escape button.

Note: This function can be invoked via the meta-object system and from QML. See Q_INVOKABLE.

### void MessageBoxHandler::setAutomaticAnswer(const QString &identifier, QMessageBox::StandardButton answer)

Sets the button that is used as the default button and that is automatically invoked if a message box is shown in automatic mode. The string identifier is used to identify the message box that the default button answer is associated to.

### void MessageBoxHandler::setDefaultAction(QInstaller::MessageBoxHandler::DefaultAction defaultAction)

Sets the default action for the message box to defaultAction.

### `[static]` QMessageBox::StandardButton MessageBoxHandler::warning(QWidget *parent, const QString &identifier, const QString &title, const QString &text, QMessageBox::StandardButtons buttons = QMessageBox::Ok, QMessageBox::StandardButton button = QMessageBox::NoButton)

Opens a warning message box with the parent parent, identifier identifier, title title, and text text.

The standard buttons specified by buttons are added to the message box. button specifies the button that is used when Enter is pressed. button must refer to a button that is specified in buttons. If button is QMessageBox::NoButton, a suitable default is chosen automatically.

Returns the identity of the standard button that was clicked. However, if Esc was pressed, returns the escape button.

### `[invokable]` int MessageBoxHandler::warning(const QString &identifier, const QString &title, const QString &text, int buttons = QMessageBox::Ok, int button = QMessageBox::NoButton)

Opens a warning message box with the identifier identifier, title title, and text text.

The standard buttons specified by buttons are added to the message box. button specifies the button that is used when Enter is pressed. button must refer to a button that is specified in buttons. If button is QMessageBox::NoButton, a suitable default is chosen automatically.

Returns the identity of the standard button that was clicked. However, if Esc was pressed, returns the escape button.

Note: This function can be invoked via the meta-object system and from QML. See Q_INVOKABLE.