QtBase
v6.3.1
|
The QGuiApplication class manages the GUI application's control flow and main settings. More...
#include <qguiapplication.h>
Signals | |
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 |
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 | |
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 | QFontDatabasePrivate |
class | QPlatformIntegration |
class | QPlatformSessionManager |
Additional Inherited Members | |
Public Types inherited from QCoreApplication | |
enum | { ApplicationFlags = QT_VERSION } |
Public Slots inherited from QCoreApplication | |
static void | quit () |
static void | exit (int retcode=0) |
Public Slots inherited from QObject | |
void | deleteLater () |
Protected Attributes inherited from QObject | |
QScopedPointer< QObjectData > | d_ptr |
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 | |
The QGuiApplication class manages the GUI application's control flow and main settings.
\macro qGuiApp
A global pointer referring to the unique application object. Only valid for use when that object is a QGuiApplication.
\inmodule QtGui
QGuiApplication 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. In addition, QGuiApplication handles most of the system-wide and application-wide settings.
For any GUI application using Qt, there is precisely one QGuiApplication object no matter whether the application has 0, 1, 2 or more windows at any given time. For non-GUI Qt applications, use QCoreApplication instead, as it does not depend on the Qt GUI module. For QWidget based Qt applications, use QApplication instead, as it provides some functionality needed for creating QWidget instances.
The QGuiApplication object is accessible through the instance() function, which returns a pointer equivalent to the global \l qApp pointer.
QGuiApplication's main areas of responsibility are: \list
Since the QGuiApplication object does so much initialization, it {must} be created before any other objects related to the user interface are created. QGuiApplication 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
Definition at line 72 of file qguiapplication.h.
QGuiApplication::QGuiApplication | ( | int & | argc, |
char ** | argv, | ||
int | flags = 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 pixmaps, bitmaps etc.).
Definition at line 654 of file qguiapplication.cpp.
QGuiApplication::~QGuiApplication | ( | ) |
Destructs the application.
Definition at line 674 of file qguiapplication.cpp.
|
protected |
Definition at line 666 of file qguiapplication.cpp.
|
static |
Returns a list of all the windows in the application.
The list is empty if there are no windows.
Definition at line 998 of file qguiapplication.cpp.
|
static |
|
signal |
|
static |
Returns the current state of the application.
You can react to application state changes to perform actions such as stopping/resuming CPU-intensive tasks, freeing/loading resources or saving/restoring application data.
Definition at line 3659 of file qguiapplication.cpp.
|
signal |
This signal is emitted when the state of the application changes.
Changes the currently active application override cursor to cursor.
This function has no effect if setOverrideCursor() was not called.
Definition at line 3974 of file qguiapplication.cpp.
|
static |
Returns the object for interacting with the clipboard.
Definition at line 3309 of file qguiapplication.cpp.
|
signal |
This signal deals with \l{Session Management}{session management}. It is emitted when the QSessionManager wants the application to commit all its data.
Usually this means saving all open files, after getting permission from the user. Furthermore you may want to provide a means by which the user can cancel the shutdown.
You should not exit the application within this signal. Instead, the session manager may or may not do this afterwards, depending on the context.
|
overrideprotectedvirtual |
Reimplemented from QCoreApplication.
Reimplemented in QApplication.
Definition at line 1996 of file qguiapplication.cpp.
|
static |
|
static |
Returns true
if Qt is set to use the system's standard colors, fonts, etc.; otherwise returns false
. The default is true
.
Definition at line 4145 of file qguiapplication.cpp.
qreal QGuiApplication::devicePixelRatio | ( | ) | const |
Returns the highest screen device pixel ratio found on the system. This is the ratio between physical pixels and device-independent pixels.
Use this function only when you don't know which window you are targeting. If you do know the target window, use QWindow::devicePixelRatio() instead.
Definition at line 1125 of file qguiapplication.cpp.
|
overrideprotectedvirtual |
\reimp
Reimplemented from QCoreApplication.
Reimplemented in MyApplication, and QApplication.
Definition at line 1960 of file qguiapplication.cpp.
|
static |
Enters the main event loop and waits until exit() is called, and 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().
To make your application perform idle processing, e.g., 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.
Definition at line 1882 of file qguiapplication.cpp.
|
static |
Returns the QObject in currently active window that will be final receiver of events tied to focus, such as key events.
Definition at line 982 of file qguiapplication.cpp.
|
signal |
This signal is emitted when final receiver of events tied to focus is changed. focusObject is the new receiver.
|
static |
Returns the QWindow that receives events tied to focus, such as key events.
Definition at line 955 of file qguiapplication.cpp.
|
signal |
This signal is emitted when the focused window changes. focusWindow is the new focused window.
|
static |
Returns the default application font.
Definition at line 3449 of file qguiapplication.cpp.
|
signal |
This signal is emitted when application fonts are loaded or removed.
|
static |
Returns the high-DPI scale factor rounding policy.
Definition at line 3698 of file qguiapplication.cpp.
|
static |
returns the input method.
The input method returns properties about the state and position of the virtual keyboard. It also provides information about the position of the current focused input element.
Definition at line 4159 of file qguiapplication.cpp.
|
inlinestatic |
Returns true
if the application's layout direction is Qt::LeftToRight; otherwise returns false
.
Definition at line 145 of file qguiapplication.h.
|
inlinestatic |
Returns true
if the application's layout direction is Qt::RightToLeft; otherwise returns false
.
Definition at line 144 of file qguiapplication.h.
bool QGuiApplication::isSavingSession | ( | ) | const |
Returns true
if the application is currently saving the \l{Session Management}{session}; otherwise returns false
.
This is true
when commitDataRequest() and saveStateRequest() are emitted, but also when the windows are closed afterwards by session management.
Definition at line 3860 of file qguiapplication.cpp.
bool QGuiApplication::isSessionRestored | ( | ) | const |
Returns true
if the application has been restored from an earlier \l{Session Management}{session}; otherwise returns false
.
Definition at line 3842 of file qguiapplication.cpp.
|
static |
Returns the current state of the modifier keys on the keyboard. The current state is updated synchronously as the event queue is emptied of events that will spontaneously change the keyboard state (QEvent::KeyPress and QEvent::KeyRelease events).
It should be noted this may not reflect the actual keys held on the input device at the time of calling but rather the modifiers as last reported in one of the above events. If no keys are being held Qt::NoModifier is returned.
Definition at line 1787 of file qguiapplication.cpp.
|
signal |
This signal is emitted from exec() when the last visible \l{Primary and Secondary Windows}{primary window} (i.e. top level window with no transient parent) is closed.
By default, QGuiApplication quits after this signal is emitted. This feature can be turned off by setting \l quitOnLastWindowClosed to false
.
|
static |
|
signal |
|
static |
Returns the most recently shown modal window. If no modal windows are visible, this function returns zero.
A modal window is a window which has its \l{QWindow::modality}{modality} property set to Qt::WindowModal or Qt::ApplicationModal. A modal window must be closed before the user can continue with other parts of the program.
Modal window are organized in a stack. This function returns the modal window at the top of the stack.
Definition at line 810 of file qguiapplication.cpp.
|
static |
Returns the current state of the buttons on the mouse. The current state is updated synchronously as the event queue is emptied of events that will spontaneously change the mouse state (QEvent::MouseButtonPress and QEvent::MouseButtonRelease events).
It should be noted this may not reflect the actual buttons held on the input device at the time of calling but rather the mouse buttons as last reported in one of the above events. If no mouse buttons are being held Qt::NoButton is returned.
Definition at line 1828 of file qguiapplication.cpp.
\reimp
Reimplemented from QCoreApplication.
Reimplemented in QApplication.
Definition at line 1946 of file qguiapplication.cpp.
|
static |
Returns the active application override cursor.
This function returns \nullptr if no application cursor has been defined (i.e. the internal cursor stack is empty).
Definition at line 3960 of file qguiapplication.cpp.
|
static |
Returns the current application palette.
Roles that have not been explicitly set will reflect the system's platform theme.
Definition at line 3341 of file qguiapplication.cpp.
|
static |
|
static |
|
static |
Definition at line 1838 of file qguiapplication.cpp.
|
static |
|
static |
Queries and returns the state of the modifier keys on the keyboard. Unlike keyboardModifiers, this method returns the actual keys held on the input device at the time of calling the method.
It does not rely on the keypress events having been received by this process, which makes it possible to check the modifiers while moving a window, for instance. Note that in most cases, you should use keyboardModifiers(), which is faster and more accurate since it contains the state of the modifiers as they were when the currently processed event was received.
Definition at line 1808 of file qguiapplication.cpp.
|
static |
|
static |
Undoes the last setOverrideCursor().
If setOverrideCursor() has been called twice, calling restoreOverrideCursor() will activate the first cursor set. Calling this function a second time restores the original widgets' cursors.
Definition at line 4086 of file qguiapplication.cpp.
|
signal |
This signal deals with \l{Session Management}{session management}. It is invoked when the \l{QSessionManager}{session manager} wants the application to preserve its state for a future session.
For example, a text editor would create a temporary file that includes the current contents of its edit buffers, the location of the cursor and other aspects of the current editing session.
You should never exit the application within this signal. Instead, the session manager may or may not do this afterwards, depending on the context. Furthermore, most session managers will very likely request a saved state immediately after the application has been started. This permits the session manager to learn about the application's restart policy.
This signal is emitted whenever a new screen screen has been added to the system.
Returns the screen at point, or \nullptr if outside of any screen.
The point is in relation to the virtualGeometry() of each set of virtual siblings. If the point maps to more than one set of virtual siblings the first match is returned. If you wish to search only the virtual desktop siblings of a known screen (for example siblings of the screen of your application window QWidget::windowHandle()->screen()
), use QScreen::virtualSiblingAt().
Definition at line 1063 of file qguiapplication.cpp.
This signal is emitted whenever a screen is removed from the system. It provides an opportunity to manage the windows on the screen before Qt falls back to moving them to the primary screen.
Returns a list of all the screens associated with the windowing system the application is connected to.
Definition at line 1047 of file qguiapplication.cpp.
QString QGuiApplication::sessionId | ( | ) | const |
Returns the current \l{Session Management}{session's} identifier.
If the application has been restored from an earlier session, this identifier is the same as it was in that previous session. The session identifier is guaranteed to be unique both for different applications and for different instances of the same application.
Definition at line 3848 of file qguiapplication.cpp.
QString QGuiApplication::sessionKey | ( | ) | const |
Returns the session key in the current \l{Session Management}{session}.
If the application has been restored from an earlier session, this key is the same as it was when the previous session ended.
The session key changes every time the session is saved. If the shutdown process is cancelled, another session key will be used when shutting down again.
Definition at line 3854 of file qguiapplication.cpp.
Definition at line 745 of file qguiapplication.cpp.
Definition at line 784 of file qguiapplication.cpp.
|
static |
Sets whether Qt should use the system's standard colors, fonts, etc., to on. By default, this is true
.
This function must be called before creating the QGuiApplication object, like this:
Definition at line 4134 of file qguiapplication.cpp.
Changes the default application font to font.
Definition at line 3465 of file qguiapplication.cpp.
|
static |
Sets the high-DPI scale factor rounding policy for the application. The policy decides how non-integer scale factors (such as Windows 150%) are handled.
The two principal options are whether fractional scale factors should be rounded to an integer or not. Keeping the scale factor as-is will make the user interface size match the OS setting exactly, but may cause painting errors, for example with the Windows style.
If rounding is wanted, then which type of rounding should be decided next. Mathematically correct rounding is supported but may not give the best visual results: Consider if you want to render 1.5x as 1x ("small UI") or as 2x ("large UI"). See the Qt::HighDpiScaleFactorRoundingPolicy enum for a complete list of all options.
This function must be called before creating the application object. The QGuiApplication::highDpiScaleFactorRoundingPolicy() accessor will reflect the environment, if set.
The default value is Qt::HighDpiScaleFactorRoundingPolicy::PassThrough.
Definition at line 3688 of file qguiapplication.cpp.
|
static |
Sets the application override cursor to cursor.
Application override cursors are intended for showing the user that the application is in a special state, for example during an operation that might take some time.
This cursor will be displayed in all the application's widgets until restoreOverrideCursor() or another setOverrideCursor() is called.
Application cursors are stored on an internal stack. setOverrideCursor() pushes the cursor onto the stack, and restoreOverrideCursor() pops the active cursor off the stack. changeOverrideCursor() changes the currently active application override cursor.
Every setOverrideCursor() must eventually be followed by a corresponding restoreOverrideCursor(), otherwise the stack will never be emptied.
Example:
Definition at line 4065 of file qguiapplication.cpp.
Changes the application palette to pal.
The color roles from this palette are combined with the system's platform theme to form the application's final palette.
Definition at line 3373 of file qguiapplication.cpp.
|
static |
Definition at line 3575 of file qguiapplication.cpp.
|
static |
Returns the application's style hints.
The style hints encapsulate a set of platform dependent properties such as double click intervals, full width selection and others.
The hints can be used to integrate tighter with the underlying platform.
Definition at line 4116 of file qguiapplication.cpp.
|
static |
Function that can be used to sync Qt state with the Window Systems state.
This function will first empty Qts events by calling QCoreApplication::processEvents(), then the platform plugin will sync up with the windowsystem, and finally Qts events will be delived by another call to QCoreApplication::processEvents();
This function is timeconsuming and its use is discouraged.
Definition at line 3895 of file qguiapplication.cpp.
Returns the top level window at the given position pos, if any.
Definition at line 1145 of file qguiapplication.cpp.
|
static |
Returns a list of the top-level windows in the application.
Definition at line 1010 of file qguiapplication.cpp.
|
static |
|
friend |
Definition at line 213 of file qguiapplication.h.
|
friend |
Definition at line 214 of file qguiapplication.h.
|
friend |
Definition at line 216 of file qguiapplication.h.
|
readwrite |
the user-visible name of this application
This name is shown to the user, for instance in window titles. It can be translated, if necessary.
If not set, the application display name defaults to the application name.
Definition at line 220 of file qguiapplication.h.
|
readwrite |
the base name of the desktop entry for this application
This is the file name, without the full path, of the desktop entry that represents this application according to the freedesktop desktop entry specification.
This property gives a precise indication of what desktop entry represents the application and it is needed by the windowing system to retrieve such information without resorting to imprecise heuristics.
The latest version of the freedesktop desktop entry specification can be obtained \l{http://standards.freedesktop.org/desktop-entry-spec/latest/}{here}.
Definition at line 220 of file qguiapplication.h.
|
readwrite |
the default layout direction for this application
On system start-up, or when the direction is explicitly set to Qt::LayoutDirectionAuto, the default layout direction depends on the application's language.
The notifier signal was introduced in Qt 5.4.
Definition at line 220 of file qguiapplication.h.
|
read |
The name of the underlying platform plugin.
The QPA platform plugins are located in {qtbase\src
\plugins\platforms}. At the time of writing, the following platform plugin names are supported:
\list
android
cocoa
is a platform plugin for \macos. directfb
eglfs
is a platform plugin for running Qt5 applications on top of EGL and OpenGL ES 2.0 without an actual windowing system (like X11 or Wayland). For more information, see \l{EGLFS}. ios
(also used for tvOS) linuxfb
writes directly to the framebuffer. For more information, see \l{LinuxFB}. minimal
is provided as an examples for developers who want to write their own platform plugins. However, you can use the plugin to run GUI applications in environments without a GUI, such as servers. minimalegl
is an example plugin. offscreen
qnx
windows
wayland
is a platform plugin for modern Linux desktops and some embedded systems. xcb
is the X11 plugin used on regular desktop Linux platforms. \endlistFor more information about the platform plugins for embedded Linux devices, see \l{Qt for Embedded Linux}.
Definition at line 220 of file qguiapplication.h.
|
read |
the primary (or default) screen of the application.
This will be the screen where QWindows are initially shown, unless otherwise specified.
The primaryScreenChanged signal was introduced in Qt 5.6.
Definition at line 220 of file qguiapplication.h.
|
readwrite |
whether the application implicitly quits when the last window is closed.
The default is true
.
If this property is true
, the applications quits when the last visible \l{Primary and Secondary Windows}{primary window} (i.e. top level window with no transient parent) is closed.
Definition at line 220 of file qguiapplication.h.
|
readwrite |
the default window icon
Definition at line 220 of file qguiapplication.h.