The QApplication class is part of the Qt C++ classes manages the GUI application's control flow and main settings.
The QApplication
class manages the gui application's control flow and main settings. QApplication specializes
QGuiApplication
with some functionality needed for QWidget-based applications. It handles widget specific initialization, finalization.
For any GUI application using Qt, there is precisely one QApplication
object, no matter whether the application has 0, 1, 2 or more windows at any given time.
Some GUI applications provide a special batch mode ie. provide command line arguments for executing tasks without manual intervention. In such non-GUI mode, it is often sufficient to instantiate a plain QCoreApplication
to avoid unnecessarily initializing resources needed for a graphical user interface.
The QApplication
object is accessible through the instance()
function that returns 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()
anddoubleClickInterval()
. 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()
andpostEvent()
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.
- It defines the application's look and feel, which is encapsulated in
a
QStyle
object. This can be changed at runtime withsetStyle()
. - 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 oftopLevelWidgets()
andcloseAllWindows()
, etc. - It manages the application's mouse cursor handling, see
setOverrideCursor()
.