QtBase
v6.3.1
|
The QApplication class manages the GUI application's control flow and main settings. More...
#include <qapplication.h>
Public Slots | |
void | setStyleSheet (const QString &sheet) |
void | setAutoSipEnabled (const bool enabled) |
bool | autoSipEnabled () const |
static void | closeAllWindows () |
static void | aboutQt () |
Public Slots inherited from QCoreApplication | |
static void | quit () |
static void | exit (int retcode=0) |
Public Slots inherited from QObject | |
void | deleteLater () |
Signals | |
void | focusChanged (QWidget *old, QWidget *now) |
Signals inherited from QGuiApplication | |
void | fontDatabaseChanged () |
void | screenAdded (QScreen *screen) |
void | screenRemoved (QScreen *screen) |
void | primaryScreenChanged (QScreen *screen) |
void | lastWindowClosed () |
void | focusObjectChanged (QObject *focusObject) |
void | focusWindowChanged (QWindow *focusWindow) |
void | applicationStateChanged (Qt::ApplicationState state) |
void | layoutDirectionChanged (Qt::LayoutDirection direction) |
void | commitDataRequest (QSessionManager &sessionManager) |
void | saveStateRequest (QSessionManager &sessionManager) |
void | applicationDisplayNameChanged () |
Signals inherited from QCoreApplication | |
void | aboutToQuit (QPrivateSignal) |
void | organizationNameChanged () |
void | organizationDomainChanged () |
void | applicationNameChanged () |
void | applicationVersionChanged () |
Signals inherited from QObject | |
void | destroyed (QObject *=nullptr) |
void | objectNameChanged (const QString &objectName, QPrivateSignal) |
Protected Member Functions | |
bool | event (QEvent *) override |
bool | compressEvent (QEvent *, QObject *receiver, QPostEventList *) override |
Protected Member Functions inherited from QGuiApplication | |
QGuiApplication (QGuiApplicationPrivate &p) | |
Protected Member Functions inherited from QCoreApplication | |
QCoreApplication (QCoreApplicationPrivate &p) | |
Protected Member Functions inherited from QObject | |
QObject * | sender () const |
int | senderSignalIndex () const |
int | receivers (const char *signal) const |
bool | isSignalConnected (const QMetaMethod &signal) const |
virtual void | timerEvent (QTimerEvent *event) |
virtual void | childEvent (QChildEvent *event) |
virtual void | customEvent (QEvent *event) |
virtual void | connectNotify (const QMetaMethod &signal) |
virtual void | disconnectNotify (const QMetaMethod &signal) |
QObject (QObjectPrivate &dd, QObject *parent=nullptr) | |
Properties | |
int | cursorFlashTime |
the text cursor's flash (blink) time in milliseconds More... | |
int | doubleClickInterval |
the time limit in milliseconds that distinguishes a double click from two consecutive mouse clicks More... | |
int | keyboardInputInterval |
the time limit in milliseconds that distinguishes a key press from two consecutive key presses More... | |
int | startDragTime |
the time in milliseconds that a mouse button must be held down before a drag and drop operation will begin More... | |
int | startDragDistance |
the minimum distance required for a drag and drop operation to start. More... | |
QString | styleSheet |
the application style sheet More... | |
bool | autoSipEnabled |
toggles automatic SIP (software input panel) visibility More... | |
Properties inherited from QGuiApplication | |
QIcon | windowIcon |
the default window icon More... | |
QString | applicationDisplayName |
the user-visible name of this application More... | |
QString | desktopFileName |
the base name of the desktop entry for this application More... | |
Qt::LayoutDirection | layoutDirection |
the default layout direction for this application More... | |
QString | platformName |
The name of the underlying platform plugin. More... | |
bool | quitOnLastWindowClosed |
whether the application implicitly quits when the last window is closed. More... | |
QScreen * | primaryScreen |
the primary (or default) screen of the application. More... | |
Properties inherited from QCoreApplication | |
QString | applicationName |
the name of this application More... | |
QString | applicationVersion |
the version of this application More... | |
QString | organizationName |
the name of the organization that wrote this application More... | |
QString | organizationDomain |
the Internet domain of the organization that wrote this application More... | |
bool | quitLockEnabled |
Whether the use of the QEventLoopLocker feature can cause the application to quit. More... | |
Properties inherited from QObject | |
QString | objectName |
the name of this object More... | |
Friends | |
class | QGraphicsWidget |
class | QGraphicsItem |
class | QGraphicsScene |
class | QGraphicsScenePrivate |
class | QWidget |
class | QWidgetPrivate |
class | QWidgetWindow |
class | QTranslator |
class | QWidgetAnimator |
class | QShortcut |
class | QLineEdit |
class | QWidgetTextControl |
class | QAction |
class | QGestureManager |
Related Functions | |
(Note that these are not member functions.) | |
bool | qt_sendSpontaneousEvent (QObject *receiver, QEvent *event) |
Related Functions inherited from QCoreApplication | |
void | qAddPostRoutine (QtCleanUpFunction ptr) |
void | qRemovePostRoutine (QtCleanUpFunction ptr) |
void * | resolveInterface (const char *name, int revision) const |
Related Functions inherited from QObject | |
template< class T > T | qobject_cast (const QObject *object) |
template< typename T > T | qFindChildqFindChildren (const QObject *obj, const QString &name)() |
template< typename T > QList< T > | qFindChildrenqFindChildren (const QObject *obj, const QString &name)() |
QObjectList | |
Additional Inherited Members | |
Public Types inherited from QCoreApplication | |
enum | { ApplicationFlags = QT_VERSION } |
Protected Attributes inherited from QObject | |
QScopedPointer< QObjectData > | d_ptr |
The QApplication class manages the GUI application's control flow and main settings.
\inmodule QtWidgets
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. For non-QWidget based Qt applications, use QGuiApplication instead, as it does not depend on the \l QtWidgets library.
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 following example shows how to dynamically create an appropriate type of application instance:
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: \list
Since the QApplication object does so much initialization, it {must} be created before any other objects related to the user interface are created. QApplication also deals with common command line arguments. Hence, it is usually a good idea to create it before any interpretation or modification of argv
is done in the application itself.
\table \header
\row
\row
\row
\row
\row
\row
\row
Definition at line 67 of file qapplication.h.
QApplication::QApplication | ( | int & | argc, |
char ** | argv, | ||
int | _internal = ApplicationFlags |
||
) |
Initializes the window system and constructs an application object with argc command line arguments in argv.
The global qApp
pointer refers to this application object. Only one application object should be created.
This application object must be constructed before any \l{QPaintDevice} {paint devices} (including widgets, pixmaps, bitmaps etc.).
All Qt programs automatically support the following command line options: \list
-style
command line option. You can also set the style for all Qt applications by setting the QT_STYLE_OVERRIDE
environment variable. Definition at line 478 of file qapplication.cpp.
|
virtual |
Cleans up any window system resources that were allocated by this application. Sets the global variable qApp
to \nullptr.
Definition at line 678 of file qapplication.cpp.
|
staticslot |
Displays a simple message box about Qt. The message includes the version number of Qt being used by the application.
This is useful for inclusion in the \uicontrol Help menu of an application, as shown in the \l{mainwindows/menus}{Menus} example.
This function is a convenience slot for QMessageBox::aboutQt().
Definition at line 1639 of file qapplication.cpp.
|
static |
Returns the active modal widget.
A modal widget is a special top-level widget which is a subclass of QDialog that specifies the modal parameter of the constructor as true. A modal widget must be closed before the user can continue with other parts of the program.
Modal widgets are organized in a stack. This function returns the active modal widget at the top of the stack.
Definition at line 667 of file qapplication.cpp.
|
static |
Returns the active popup widget.
A popup widget is a special top-level widget that sets the Qt::WType_Popup
widget flag, e.g. the QMenu widget. When the application opens a popup widget, all events are sent to the popup. Normal widgets and modal widgets cannot be accessed before the popup widget is closed.
Only other popup widgets may be opened when a popup widget is shown. The popup widgets are organized in a stack. This function returns the active popup widget at the top of the stack.
Definition at line 646 of file qapplication.cpp.
|
static |
Returns the application top-level window that has the keyboard input focus, or \nullptr if no application window has the focus. There might be an activeWindow() even if there is no focusWidget(), for example if no widget in that window accepts key events.
Definition at line 1560 of file qapplication.cpp.
Causes an alert to be shown for widget if the window is not the active window. The alert is shown for msec milliseconds. If msec is zero (the default), then the alert is shown indefinitely until the window becomes active again.
Currently this function does nothing on Qt for Embedded Linux.
On \macos, this works more at the application level and will cause the application icon to bounce in the dock.
On Windows, this causes the window's taskbar entry to flash for a time. If msec is zero, the flashing will stop and the taskbar entry will turn a different color (currently orange).
On X11, this will cause the window to be marked as "demands attention", the window must not be hidden (i.e. not have hide() called on it, but be visible in some sort of way) in order for this to work.
Definition at line 3543 of file qapplication.cpp.
|
static |
Returns a list of all the widgets in the application.
The list is empty (QList::isEmpty()) if there are no widgets.
Example:
Definition at line 1476 of file qapplication.cpp.
|
slot |
Definition at line 870 of file qapplication.cpp.
|
static |
Sounds the bell, using the default volume and sound. The function is not available in Qt for Embedded Linux.
Definition at line 3724 of file qapplication.cpp.
|
staticslot |
Closes all top-level windows.
This function is particularly useful for applications with many top-level windows.
The windows are closed in random order, until one window does not accept the close event. The application quits when the last window was successfully closed, unless \l quitOnLastWindowClosed is set to false. To trigger application termination from e.g. a menu, use QCoreApplication::quit() instead of this function.
Definition at line 1624 of file qapplication.cpp.
|
overrideprotectedvirtual |
Reimplemented from QGuiApplication.
Definition at line 806 of file qapplication.cpp.
|
static |
|
static |
|
overrideprotectedvirtual |
\reimp
Reimplemented from QGuiApplication.
Reimplemented in MyApplication.
Definition at line 1664 of file qapplication.cpp.
|
static |
Enters the main event loop and waits until exit() is called, then returns the value that was set to exit() (which is 0 if exit() is called via quit()).
It is necessary to call this function to start event handling. The main event loop receives events from the window system and dispatches these to the application widgets.
Generally, no user interaction can take place before calling exec(). As a special case, modal widgets like QMessageBox can be used before calling exec(), because modal widgets call exec() to start a local event loop.
To make your application perform idle processing, i.e., executing a special function whenever there are no pending events, use a QTimer with 0 timeout. More advanced idle processing schemes can be achieved using processEvents().
We recommend that you connect clean-up code to the \l{QCoreApplication::}{aboutToQuit()} signal, instead of putting it in your application's {main()} function. This is because, on some platforms the QApplication::exec() call may not return. For example, on the Windows platform, when the user logs off, the system terminates the process after Qt closes all top-level windows. Hence, there is {no guarantee} that the application will have time to exit its event loop and execute code at the end of the
{main()} function, after the QApplication::exec() call.
Definition at line 2629 of file qapplication.cpp.
This signal is emitted when the widget that has keyboard focus changed from old to now, i.e., because the user pressed the tab-key, clicked into a widget or changed the active window. Both old and now can be \nullptr.
The signal is emitted after both widget have been notified about the change through QFocusEvent.
|
static |
Returns the application widget that has the keyboard input focus, or \nullptr if no widget in this application has the focus.
Definition at line 1490 of file qapplication.cpp.
|
static |
Returns the default application font.
Definition at line 1266 of file qapplication.cpp.
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
Returns the font for widgets of the given className.
Definition at line 1317 of file qapplication.cpp.
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
Returns the default font for the widget. If a default font was not registered for the {widget}'s class, it returns the default font of its nearest registered superclass.
Definition at line 1281 of file qapplication.cpp.
|
static |
Returns true
if effect is enabled; otherwise returns false
.
By default, Qt will try to use the desktop settings. To prevent this, call setDesktopSettingsAware(false).
Definition at line 3710 of file qapplication.cpp.
|
static |
\reimp
Reimplemented from QGuiApplication.
Definition at line 2636 of file qapplication.cpp.
|
static |
Returns the current application palette.
Roles that have not been explicitly set will reflect the system's platform theme.
Definition at line 134 of file qguiapplication.cpp.
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
Returns the palette for widgets of the given className.
Definition at line 1145 of file qapplication.cpp.
If a widget is passed, the default palette for the widget's class is returned. This may or may not be the application palette. In most cases there is no special palette for certain types of widgets, but one notable exception is the popup menu under Windows, if the user has defined a special background color for menus in the display settings.
Definition at line 1122 of file qapplication.cpp.
Sets the active window to the active widget in response to a system event. The function is called from the platform specific event handlers.
It sets the activeWindow() and focusWidget() attributes and sends proper \l{QEvent::WindowActivate}{WindowActivate}/\l{QEvent::WindowDeactivate} {WindowDeactivate} and \l{QEvent::FocusIn}{FocusIn}/\l{QEvent::FocusOut} {FocusOut} events to all appropriate widgets. The window will then be painted in active state (e.g. cursors in line edits will blink), and it will have tool tips enabled.
Definition at line 1791 of file qapplication.cpp.
Definition at line 865 of file qapplication.cpp.
|
static |
|
static |
|
static |
Enables the UI effect effect if enable is true, otherwise the effect will not be used.
Definition at line 3683 of file qapplication.cpp.
Changes the default application font to font. If className is passed, the change applies only to classes that inherit className (as reported by QObject::inherits()).
On application start-up, the default font depends on the window system. It can vary depending on both the window system version and the locale. This function lets you override the default font; but overriding may be a bad idea because, for example, some locales need extra large fonts to support their special characters.
Definition at line 1348 of file qapplication.cpp.
|
static |
Changes the application palette to palette.
If className is passed, the change applies only to widgets that inherit className (as reported by QObject::inherits()). If className is left 0, the change affects all widgets, thus overriding any previously set class specific palettes.
The palette may be changed according to the current GUI style in QStyle::polish().
Definition at line 1179 of file qapplication.cpp.
|
static |
|
static |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
Requests a QStyle object for style from the QStyleFactory.
The string must be one of the QStyleFactory::keys(), typically one of "windows", "windowsvista", "fusion", or "macos". Style names are case insensitive.
Returns \nullptr if an unknown style is passed, otherwise the QStyle object returned is set as the application's GUI style.
Definition at line 1075 of file qapplication.cpp.
Sets the application's GUI style to style. Ownership of the style object is transferred to QApplication, so QApplication will delete the style object on application exit or when a new style is set and the old style is still the parent of the application object.
Example usage:
When switching application styles, the color palette is set back to the initial colors or the system defaults. This is necessary since certain styles have to adapt the color palette to be fully style-guide compliant.
Setting the style before a palette has been set, i.e., before creating QApplication, will cause the application to use QStyle::standardPalette() for the palette.
Definition at line 970 of file qapplication.cpp.
Definition at line 882 of file qapplication.cpp.
|
static |
|
static |
|
static |
Returns the application's style object.
Definition at line 906 of file qapplication.cpp.
QString QApplication::styleSheet | ( | ) | const |
Definition at line 877 of file qapplication.cpp.
Returns the top-level widget at the given point; returns \nullptr if there is no such widget.
Definition at line 316 of file qapplication.cpp.
|
inlinestatic |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
Returns the top-level widget at the point ({x}, {y}); returns 0 if there is no such widget.
Definition at line 122 of file qapplication.h.
|
static |
Returns a list of the top-level widgets (windows) in the application.
Example:
Definition at line 1450 of file qapplication.cpp.
Returns the widget at global screen position point, or \nullptr if there is no Qt widget there.
This function can be slow.
Definition at line 757 of file qapplication.cpp.
|
inlinestatic |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
Returns the widget at global screen position (x, y), or \nullptr if there is no Qt widget there.
Definition at line 120 of file qapplication.h.
|
friend |
Definition at line 195 of file qapplication.h.
|
friend |
Definition at line 198 of file qapplication.h.
|
friend |
Definition at line 182 of file qapplication.h.
|
friend |
Definition at line 183 of file qapplication.h.
|
friend |
Definition at line 184 of file qapplication.h.
|
friend |
Definition at line 181 of file qapplication.h.
|
friend |
Definition at line 192 of file qapplication.h.
|
friend |
Definition at line 191 of file qapplication.h.
\macro qApp
A global pointer referring to the unique application object. It is equivalent to QCoreApplication::instance(), but cast as a QApplication pointer, so only valid when the unique application object is a QApplication.
Definition at line 3740 of file qapplication.cpp.
|
friend |
Definition at line 188 of file qapplication.h.
|
friend |
Definition at line 185 of file qapplication.h.
|
friend |
Definition at line 189 of file qapplication.h.
|
friend |
Definition at line 186 of file qapplication.h.
|
friend |
Definition at line 193 of file qapplication.h.
|
friend |
Definition at line 187 of file qapplication.h.
|
readwrite |
toggles automatic SIP (software input panel) visibility
Set this property to true
to automatically display the SIP when entering widgets that accept keyboard input. This property only affects widgets with the WA_InputMethodEnabled attribute set, and is typically used to launch a virtual keyboard on devices which have very few or no keys.
{ The property only has an effect on platforms that use software input panels.}
The default is platform dependent.
Definition at line 202 of file qapplication.h.
|
readwrite |
the text cursor's flash (blink) time in milliseconds
The flash time is the time required to display, invert and restore the caret display. Usually the text cursor is displayed for half the cursor flash time, then hidden for the same amount of time, but this may vary.
The default value on X11 is 1000 milliseconds. On Windows, the \uicontrol{Control Panel} value is used and setting this property sets the cursor flash time for all applications.
We recommend that widgets do not cache this value as it may change at any time if the user changes the global desktop settings.
Definition at line 202 of file qapplication.h.
|
readwrite |
the time limit in milliseconds that distinguishes a double click from two consecutive mouse clicks
The default value on X11 is 400 milliseconds. On Windows and Mac OS, the operating system's value is used.
Definition at line 202 of file qapplication.h.
|
readwrite |
the time limit in milliseconds that distinguishes a key press from two consecutive key presses
The default value on X11 is 400 milliseconds. On Windows and Mac OS, the operating system's value is used.
Definition at line 202 of file qapplication.h.
|
readwrite |
the minimum distance required for a drag and drop operation to start.
If you support drag and drop in your application, and want to start a drag and drop operation after the user has moved the cursor a certain distance with a button held down, you should use this property's value as the minimum distance required.
For example, if the mouse position of the click is stored in startPos
and the current position (e.g. in the mouse move event) is currentPos
, you can find out if a drag should be started with code like this:
Qt uses this value internally, e.g. in QFileDialog.
The default value (if the platform doesn't provide a different default) is 10 pixels.
Definition at line 202 of file qapplication.h.
|
readwrite |
the time in milliseconds that a mouse button must be held down before a drag and drop operation will begin
If you support drag and drop in your application, and want to start a drag and drop operation after the user has held down a mouse button for a certain amount of time, you should use this property's value as the delay.
Qt also uses this delay internally, e.g. in QTextEdit and QLineEdit, for starting a drag.
The default value is 500 ms.
Definition at line 202 of file qapplication.h.
|
readwrite |
the application style sheet
By default, this property returns an empty string unless the user specifies the {-stylesheet} option on the command line when running the application.
Definition at line 202 of file qapplication.h.