|  | Home · Overviews · Examples

# QApplication Class Reference
[com.trolltech.qt.gui module]

The QApplication class manages the GUI application's control flow and main settings. More...

Inherits `QCoreApplication`.

## Detailed Description

The QApplication class manages the GUI application's control flow and main settings.

It contains the main event loop, where all events from the window system and other sources are processed and dispatched. It also handles the application's initialization and finalization, and provides session management. It also handles most system-wide and application-wide settings.

For any GUI application that uses Qt, there is precisely one QApplication object, no matter whether the application has 0, 1, 2 or more windows at any time. For non-GUI Qt applications, use `QCoreApplication` instead, which doesn't depend on the `QtGui` library.

The QApplication object is accessible through the `instance` function which return a pointer equivalent to the global qApp pointer.

QApplication's main areas of responsibility are:

- It initializes the application with the user's desktop settings such as `palette`, `font` and `doubleClickInterval`. It keeps track of these properties in case the user changes the desktop globally, for example through some kind of control panel.
- It performs event handling, meaning that it receives events from the underlying window system and dispatches them to the relevant widgets. By using `sendEvent` and `postEvent` you can send your own events to widgets.
- It parses common command line arguments and sets its internal state accordingly. See the constructor documentation below for more details about this.
- It defines the application's look and feel, which is encapsulated in a `QStyle` object. This can be changed at runtime with `setStyle`.
- It specifies how the application is to allocate colors. See `setColorSpec` for details.
- It provides localization of strings that are visible to the user via translate().
- It provides some magical objects like the `desktop` and the `clipboard`.
- It knows about the application's windows. You can ask which widget is at a certain position using `widgetAt`, get a list of `topLevelWidgets` and `closeAllWindows`, etc.
- It manages the application's mouse cursor handling, see `setOverrideCursor`
- On the X window system, it provides functions to flush and sync the communication stream, see flushX() and `syncX`.
- It provides support for sophisticated session management. This makes it possible for applications to terminate gracefully when the user logs out, to cancel a shutdown process if termination isn't possible and even to preserve the entire application's state for a future session. See `isSessionRestored`, `sessionId` and `commitData` and `saveState` for details.

Since the QApplication object does so much initialization, it must be created before any other objects related to the user interface are created.

Since it also deals with common command line arguments, it is usually a good idea to create it before any interpretation or modification of `argv` is done in the application itself.

Groups of functions
System settings | `desktopSettingsAware`, `setDesktopSettingsAware`, `cursorFlashTime`, `setCursorFlashTime`, `doubleClickInterval`, `setDoubleClickInterval`, `setKeyboardInputInterval`, `wheelScrollLines`, `setWheelScrollLines`, `palette`, setPalette(), `font`, setFont(), `fontMetrics`.
Event handling | `exec`, `processEvents`, `exit`, `quit`. `sendEvent`, `postEvent`, `sendPostedEvents`, `removePostedEvents`, `hasPendingEvents`, `notify`, macEventFilter(), qwsEventFilter(), x11EventFilter(), x11ProcessEvent(), winEventFilter().
GUI Styles | `style`, `setStyle`.
Color usage | `colorSpec`, `setColorSpec`, qwsSetCustomColors().
Text handling | `installTranslator`, `removeTranslator` translate().
Widgets | `allWidgets`, `topLevelWidgets`, `desktop`, `activePopupWidget`, `activeModalWidget`, `clipboard`, `focusWidget`, winFocus(), `activeWindow`, `widgetAt`.
Advanced cursor handling | overrideCursor(), `setOverrideCursor`, `restoreOverrideCursor`.
X Window System synchronization | flushX(), `syncX`.
Session management | `isSessionRestored`, `sessionId`, `commitData`, `saveState`.
Miscellaneous | `closeAllWindows`, `startingUp`, `closingDown`, `type`.

See also `QCoreApplication`, `QAbstractEventDispatcher`, `QEventLoop`, and `QSettings`.