6.0.0-rc4Source

QGuiApplication Class

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

Header#include <QGuiApplication>
CMaketarget_link_libraries(app PRIVATE Nt::Gui)
ModuleNt GUI C++ Classes
InheritsQCoreApplication
Inherited byQApplication

List of all members, including inherited members

Public Functions

QGuiApplication(int &argc, char **argv)
~QGuiApplication()

Signals

voidlastWindowClosed()
voidscreenAdded(QScreen *screen)
voidscreenRemoved(QScreen *screen)
voidfocusWindowChanged(QWindow *focusWindow)

Static Public Members

Detailed Description

QGuiApplication adds to QCoreApplication what graphical programs need: it connects to the window system, owns the screens, and delivers input events to windows. Create one in main() before any QWindow:

int main(int argc, char *argv[])
{
    QGuiApplication app(argc, argv);
    MyWindow window;
    window.show();
    return app.exec();
}

The platform is chosen from the -platform command line option, then from the QT_QPA_PLATFORM environment variable, and otherwise it is xcb if DISPLAY is set and offscreen if not. An unknown or unavailable platform aborts the program, as in Qt.

See also QCoreApplication, QWindow and QScreen.

Differences from Qt

Only the functions below exist. There is no clipboard, no style hints, no palette or font, no translators, no high-DPI settings, no queryKeyboardModifiers() and no session management. The -platform option stays in arguments(). Platform options after a colon (xcb:foo) are ignored. There are no platform plugins: the platforms are built in. qApp is not redefined by Nt GUI; use qGuiApp.

Member Function Documentation

QGuiApplication::QGuiApplication(int &argc, char **argv)

Constructs a GUI application from argc and argv, as QCoreApplication does, and connects to the window system. The program aborts if the platform cannot be started.

[override] QGuiApplication::~QGuiApplication()

Destroys the application object: the platform windows are released and the connection to the window system is closed.

[static] QList<QWindow *> QGuiApplication::allWindows()

Returns all windows of the application, visible or not.

See also topLevelWindows().

[static] void QGuiApplication::changeOverrideCursor(const QCursor &cursor)

Replaces the override cursor that shows with cursor. Nothing happens if there is no override cursor.

See also setOverrideCursor().

[static] QWindow * QGuiApplication::focusWindow()

Returns the window that has the keyboard focus, or nullptr.

[signal] void QGuiApplication::focusWindowChanged(QWindow *focusWindow)

This signal is emitted when the window that has the keyboard focus changes to focusWindow.

[static] QFont QGuiApplication::font()

Returns the default font of the application: the font that QFont() constructs. It is "Sans Serif" at 10 points until setFont() changes it.

See also setFont().

[static] QGuiApplication * QGuiApplication::instance()

Returns the application object, or nullptr if there is none or it is not a QGuiApplication.

[static] Qt::KeyboardModifiers QGuiApplication::keyboardModifiers()

Returns the modifier keys that were down at the last key or mouse event.

[signal] void QGuiApplication::lastWindowClosed()

This signal is emitted from the application when the last visible window is closed, before the application quits if quitOnLastWindowClosed() is true.

[static] Qt::MouseButtons QGuiApplication::mouseButtons()

Returns the mouse buttons that were down at the last mouse event.

[static] QCursor * QGuiApplication::overrideCursor()

Returns the override cursor that shows, or nullptr if there is none. The pointer is valid until the override cursors change.

See also setOverrideCursor().

[static] QString QGuiApplication::platformName()

Returns the name of the platform, such as "xcb" or "offscreen".

[static] QScreen * QGuiApplication::primaryScreen()

Returns the primary screen, or nullptr if there are none.

See also screens().

[static] bool QGuiApplication::quitOnLastWindowClosed()

Returns whether the application quits when its last visible window closes. The default is true.

See also setQuitOnLastWindowClosed().

[static] void QGuiApplication::restoreOverrideCursor()

Takes away the override cursor that was set last. The one before it shows again, or, after the last one, the cursors of the windows. Nothing happens if there is no override cursor.

See also setOverrideCursor().

[signal] void QGuiApplication::screenAdded(QScreen *screen)

This signal is emitted when screen is added.

[signal] void QGuiApplication::screenRemoved(QScreen *screen)

This signal is emitted when screen is removed.

[static] QList<QScreen *> QGuiApplication::screens()

Returns all screens; the primary screen comes first.

[static] void QGuiApplication::setFont(const QFont &font)

Sets the default font of the application to font. It applies to fonts constructed afterwards.

See also font().

[static] void QGuiApplication::setOverrideCursor(const QCursor &cursor)

Sets the cursor of the whole application to cursor: it shows over every window, whatever cursors the windows and their widgets have, until restoreOverrideCursor() takes it away again. Override cursors stack: each call needs a restoreOverrideCursor() of its own, and the cursor of the last call is the one that shows.

QGuiApplication::setOverrideCursor(Qt::WaitCursor);
compute();
QGuiApplication::restoreOverrideCursor();

See also restoreOverrideCursor(), changeOverrideCursor() and overrideCursor().

[static] void QGuiApplication::setQuitOnLastWindowClosed(bool quit)

Sets whether the application quits when its last visible window closes to quit. The default is true.

See also quitOnLastWindowClosed() and lastWindowClosed().

[static] QStyleHints * QGuiApplication::styleHints()

Returns the style hints of the application, such as its color scheme. They exist as long as the application object does.

[static] QList<QWindow *> QGuiApplication::topLevelWindows()

Returns the top-level windows of the application. Every window is a top-level window, so this is the same as allWindows().