- Extending Qt Creator Manual
- ICore
- Extending Qt Creator Manual 8.0.2

# ICore Class

class Core::ICore

The ICore class allows access to the different parts that make up the basic functionality of Qt Creator. More...

Header: | #include <coreplugin/icore.h>

- List of all members, including inherited members

## Public Types

enum class | ContextPriority { High, Low }

## Signals

void | contextAboutToChange(const QList<Core::IContext *> &context)
void | contextChanged(const Core::Context &context)
void | coreAboutToClose()
void | coreAboutToOpen()
void | coreOpened()
void | saveSettingsRequested(Core::ICore::SaveSettingsReason reason)

## Static Public Members

void | addAdditionalContext(const Core::Context &context, Core::ICore::ContextPriority priority = ContextPriority::Low)
void | addContextObject(Core::IContext *context)
void | addPreCloseListener(const std::function<bool ()> &listener)
Utils::FilePath | cacheResourcePath(const QString &rel = {})
Core::IContext * | contextObject(QWidget *widget)
Core::IContext * | currentContextObject()
QWidget * | currentContextWidget()
QWidget * | dialogParent()
Utils::InfoBar * | infoBar()
Utils::FilePath | installerResourcePath(const QString &rel = {})
Core::ICore * | instance()
bool | isNewItemDialogRunning()
Utils::FilePath | libexecPath(const QString &rel = {})
QMainWindow * | mainWindow()
QString | msgShowOptionsDialog()
QString | msgShowOptionsDialogToolTip()
QWidget * | newItemDialog()
void | openFiles(const Utils::FilePaths &filePaths, Core::ICore::OpenFilesFlags flags = None)
QPrinter * | printer()
void | raiseWindow(QWidget *widget)
void | registerWindow(QWidget *window, const Core::Context &context)
void | removeAdditionalContext(const Core::Context &context)
void | removeContextObject(Core::IContext *context)
Utils::FilePath | resourcePath(const QString &rel = {})
void | restart()
Utils::QtcSettings * | settings(QSettings::Scope scope = QSettings::UserScope)
Core::SettingsDatabase * | settingsDatabase()
void | showNewItemDialog(const QString &title, const QList<Core::IWizardFactory *> &factories, const Utils::FilePath &defaultLocation = {}, const QVariantMap &extraVariables = {})
bool | showOptionsDialog(const Utils::Id page, QWidget *parent = nullptr)
bool | showWarningWithOptions(const QString &title, const QString &text, const QString &details = QString(), Utils::Id settingsId = {}, QWidget *parent = nullptr)
void | updateAdditionalContexts(const Core::Context &remove, const Core::Context &add, Core::ICore::ContextPriority priority = ContextPriority::Low)
QString | userInterfaceLanguage()
Utils::FilePath | userResourcePath(const QString &rel = {})
QString | versionString()

## Detailed Description

You should never create a subclass of this interface. The one and only instance is created by the Core plugin. You can access this instance from your plugin through instance().

## Member Type Documentation

### enum class ICore::ContextPriority

This enum defines the priority of additional contexts.

Constant | Value | Description
--- | --- | ---
`Core::ICore::ContextPriority::High` | `0` | Additional contexts that have higher priority than contexts from Core::IContext instances.
`Core::ICore::ContextPriority::Low` | `1` | Additional contexts that have lower priority than contexts from Core::IContext instances.

See also Core::ICore::updateAdditionalContexts().

## Member Function Documentation

### `[signal]` void ICore::contextAboutToChange(const QList<Core::IContext *> &context)

Indicates that a new context will shortly become the current context (meaning that its widget got focus).

### `[signal]` void ICore::contextChanged(const Core::Context &context)

Indicates that a new context just became the current context. This includes the context from the focus object as well as the additional context.

### `[signal]` void ICore::coreAboutToClose()

Enables plugins to perform some pre-end-of-life actions.

The application is guaranteed to shut down after this signal is emitted. It is there as an addition to the usual plugin lifecycle functions, namely `IPlugin::aboutToShutdown()`, just for convenience.

### `[signal]` void ICore::coreAboutToOpen()

Indicates that all plugins have been loaded and the main window is about to be shown.

### `[signal]` void ICore::coreOpened()

Indicates that all plugins have been loaded and the main window is shown.

### `[signal]` void ICore::saveSettingsRequested(Core::ICore::SaveSettingsReason reason)

Signals that the user has requested that the global settings should be saved to disk for a reason.

At the moment that happens when the application is closed, and on Save All.

### `[static]` void ICore::addAdditionalContext(const Core::Context &context, Core::ICore::ContextPriority priority = ContextPriority::Low)

Adds context with priority to the list of active additional contexts.

See also updateAdditionalContexts().

### `[static]` void ICore::addContextObject(Core::IContext *context)

Adds context to the list of registered IContext instances. Whenever the IContext's widget is in the application focus widget's parent hierarchy, its context is added to the list of active contexts.

See also removeContextObject(), updateAdditionalContexts(), currentContextObject(), and The Action Manager and Commands.

### `[static]` void ICore::addPreCloseListener(const std::function<bool ()> &listener)

Provides a hook for plugins to veto on closing the application.

When the application window requests a close, all listeners are called. If one of the listener calls returns `false`, the process is aborted and the event is ignored. If all calls return `true`, coreAboutToClose() is emitted and the event is accepted or performed.

### `[static]` Utils::FilePath ICore::cacheResourcePath(const QString &rel = {})

Returns a writable path for the relative path rel that can be used for persistent cache files.

### `[static]` Core::IContext *ICore::contextObject(QWidget *widget)

Returns the registered IContext instance for the specified widget, if any.

### `[static]` Core::IContext *ICore::currentContextObject()

Returns the top level IContext of the current context, or `nullptr` if there is none.

See also updateAdditionalContexts(), addContextObject(), and The Action Manager and Commands.

### `[static]` QWidget *ICore::currentContextWidget()

Returns the widget of the top level IContext of the current context, or `nullptr` if there is none.

See also currentContextObject().

### `[static]` QWidget *ICore::dialogParent()

Returns a widget pointer suitable to use as parent for QDialogs.

### `[static]` Utils::InfoBar *ICore::infoBar()

Returns a central InfoBar that is shown in Qt Creator's main window. Use for notifying the user of something without interrupting with dialog. Use sparingly.

### `[static]` Utils::FilePath ICore::installerResourcePath(const QString &rel = {})

Returns the path, based on the relative path rel, to resources written by the installer, for example pre-defined kits and toolchains.

### `[static]` Core::ICore *ICore::instance()

Returns the pointer to the instance. Only use for connecting to signals.

### `[static]` bool ICore::isNewItemDialogRunning()

Returns whether the new item dialog is currently open.

### `[static]` Utils::FilePath ICore::libexecPath(const QString &rel = {})

Returns the path, based on the relative path rel, to the command line tools that are included in the Qt Creator installation.

### `[static]` QMainWindow *ICore::mainWindow()

Returns the main window of the application.

For dialog parents use dialogParent().

See also dialogParent().

### `[static]` QString ICore::msgShowOptionsDialog()

Returns the text to use on buttons that open the options dialog.

See also showOptionsDialog() and msgShowOptionsDialogToolTip().

### `[static]` QString ICore::msgShowOptionsDialogToolTip()

Returns the tool tip to use on buttons that open the options dialog.

See also showOptionsDialog() and msgShowOptionsDialog().

### `[static]` QWidget *ICore::newItemDialog()

Returns the currently open new item dialog widget, or `nullptr` if there is none.

See also isNewItemDialogRunning() and showNewItemDialog().

### `[static]` void ICore::openFiles(const Utils::FilePaths &filePaths, Core::ICore::OpenFilesFlags flags = None)

Opens files using filePaths and flags like it would be done if they were given to Qt Creator on the command line, or they were opened via File > Open.

### `[static]` QPrinter *ICore::printer()

Returns the application's printer object.

Always use this printer object for printing, so the different parts of the application re-use its settings.

### `[static]` void ICore::raiseWindow(QWidget *widget)

Raises and activates the window for widget. This contains workarounds for X11.

### `[static]` void ICore::registerWindow(QWidget *window, const Core::Context &context)

Registers a window with the specified context. Registered windows are shown in the Window menu and get registered for the various window related actions, like the minimize, zoom, fullscreen and close actions.

Whenever the application focus is in window, its context is made active.

### `[static]` void ICore::removeAdditionalContext(const Core::Context &context)

Removes context from the list of active additional contexts.

See also updateAdditionalContexts().

### `[static]` void ICore::removeContextObject(Core::IContext *context)

Unregisters a context object from the list of registered IContext instances. IContext instances are automatically removed when they are deleted.

See also addContextObject(), updateAdditionalContexts(), and currentContextObject().

### `[static]` Utils::FilePath ICore::resourcePath(const QString &rel = {})

Returns the absolute path for the relative path rel that is used for resources like project templates and the debugger macros.

This abstraction is needed to avoid platform-specific code all over the place, since on macOS, for example, the resources are part of the application bundle.

See also userResourcePath().

### `[static]` void ICore::restart()

Restarts Qt Creator and restores the last session.

### `[static]` Utils::QtcSettings *ICore::settings(QSettings::Scope scope = QSettings::UserScope)

Returns the application's main settings object.

You can use it to retrieve or set application-wide settings (in contrast to session or project specific settings).

If scope is `QSettings::UserScope` (the default), the settings will be read from the user's settings, with a fallback to global settings provided with Qt Creator.

If scope is `QSettings::SystemScope`, only the installation settings shipped with the current version of Qt Creator will be read. This functionality exists for internal purposes only.

See also settingsDatabase().

### `[static]` Core::SettingsDatabase *ICore::settingsDatabase()

Returns the application's settings database.

The settings database is meant as an alternative to the regular settings object. It is more suitable for storing large amounts of data. The settings are application wide.

See also SettingsDatabase and settings().

### `[static]` void ICore::showNewItemDialog(const QString &title, const QList<Core::IWizardFactory *> &factories, const Utils::FilePath &defaultLocation = {}, const QVariantMap &extraVariables = {})

Opens a dialog where the user can choose from a set of factories that create new files or projects.

The title argument is shown as the dialog title. The path where the files will be created (if the user does not change it) is set in defaultLocation. Defaults to DocumentManager::projectsDirectory() or DocumentManager::fileDialogLastVisitedDirectory(), depending on wizard kind.

Additional variables for the wizards are set in extraVariables.

See also Core::DocumentManager, isNewItemDialogRunning(), and newItemDialog().

### `[static]` bool ICore::showOptionsDialog(const Utils::Id page, QWidget *parent = nullptr)

Opens the options dialog on the specified page. The dialog's parent defaults to dialogParent(). If the dialog is already shown when this method is called, it is just switched to the specified page.

Returns whether the user accepted the dialog.

See also msgShowOptionsDialog() and msgShowOptionsDialogToolTip().

### `[static]` bool ICore::showWarningWithOptions(const QString &title, const QString &text, const QString &details = QString(), Utils::Id settingsId = {}, QWidget *parent = nullptr)

Creates a message box with parent that contains a Configure button for opening the settings page specified by settingsId.

The dialog has title and displays the message text and detailed information specified by details.

Use this function to display configuration errors and to point users to the setting they should fix.

Returns `true` if the user accepted the settings dialog.

See also showOptionsDialog().

### `[static]` void ICore::updateAdditionalContexts(const Core::Context &remove, const Core::Context &add, Core::ICore::ContextPriority priority = ContextPriority::Low)

Removes the contexts specified by remove from the list of active additional contexts, and adds the contexts specified by add with priority.

The additional contexts are not associated with an IContext instance.

High priority additional contexts have higher priority than the contexts added by IContext instances, low priority additional contexts have lower priority than the contexts added by IContext instances.

See also addContextObject() and The Action Manager and Commands.

### `[static]` QString ICore::userInterfaceLanguage()

Returns the locale string for the user interface language that is currently configured in Qt Creator. Use this to install your plugin's translation file with QTranslator.

### `[static]` Utils::FilePath ICore::userResourcePath(const QString &rel = {})

Returns the absolute path for the relative path rel in the users directory that is used for resources like project templates.

Use this function for finding the place for resources that the user may write to, for example, to allow for custom palettes or templates.

See also resourcePath().

### `[static]` QString ICore::versionString()

Returns a string with the IDE's name and version, in the form "Qt Creator X.Y.Z". Use this for "Generated by" strings and similar tasks.