Qt Platform Abstraction

The Qt Platform Abstraction (QPA) is the main platform abstraction layer in Qt.

The API can be identified by the QPlatform* class prefix, and is used for implementing higher level classes typically found in Qt GUI ,如 QPlatformWindow for window system integration exposed through QWindow ,或 QPlatformTheme for deeper platform theming and integration, exposed through QStyleHint and QStyle .

There are no source or binary compatibility guarantees for the QPA classes, meaning that the API is only guaranteed to work with the Qt version it was developed against. API changes will however only be made in minor releases. (5.1, 5.2, and so on.)

API Overview

  • Window system integration
    • QPlatformIntegration
    • QPlatformAccessibility
    • QPlatformBackingStore
    • QPlatformClipboard
    • QPlatformCursor
    • QPlatformDrag
    • QPlatformFontDatabase
    • QPlatformGraphicsBuffer
    • QPlatformInputContext
    • QPlatformOffscreenSurface
    • QPlatformOpenGLContext
    • QPlatformScreen
    • QPlatformServices
    • QPlatformSharedGraphicsCache
    • QPlatformSurface
    • QPlatformWindow
  • Style/theming
    • QPlatformTheme
    • platform palettes
    • platform fonts
    • theme hints
  • Native dialogs and menus
    • QPlatformDialogHelper
    • QPlatformMenu
    • QPlatformMenuBar
    • QPlatformMenuItem

注意: In addition to the QPA APIs, there are many other platform abstractions in Qt, for example the event dispatcher abstractions in Qt Core and the rendering hardware abstractions in RHI. The QPA APIs are mostly focused on window system integration and related support.

QPA 插件

Concrete implementations of the interfaces listed above live in QPA plugins, or platform plugins, adding support for the various platforms Qt runs on. QPA plugins are implemented by subclassing the QPlatform* 类。

The following table summarizes the platform plugins available:

插件名称 插件类名 描述
qandroid QAndroidPlatformIntegration Android 支持
qbsdfb QBsdFbIntegration BsdFb 支持
qcocoa QCocoaIntegrationPlugin macOS support
qdirect2d QWindowsDirect2DIntegrationPlugin 类似于 qwindows 插件,但采用基于 Direct2D 的描绘引擎替换光栅描绘引擎为 QPixmap and QBackingStore .
qdirectfb QDirectFbIntegrationPlugin DirectFB 中心围绕 surfaces ,相当于 QPaintDevice .
qeglfs QEglFSIntegrationPlugin EGLFS 支持嵌入式 Linux 设备。
qhaiku QHaikuIntegration Haiku 支持
qios QIOSIntegrationPlugin iOS 支持
qlinuxfb QLinuxFbIntegrationPlugin LinuxFB 支持嵌入式 Linux 设备。
qvnc QVncIntegration VNC 支持
qwayland
  • QWaylandIntegrationPlugin
  • QWaylandBrcmEglPlatformIntegrationPlugin
  • QWaylandEglPlatformIntegrationPlugin
  • QWaylandXCompositeEglPlatformIntegrationPlugin
  • QWaylandXCompositeGlxPlatformIntegrationPlugin
Wayland 支持
qwindows QWindowsIntegrationPlugin Windows 支持
qxcb QXcbIntegrationPlugin X 窗口系统 (X11) 支持

Selecting a QPA plugin

Qt will select a default QPA plugin, depending on the platform. The QT_QPA_PLATFORM environment variable and the -platform command line argument allow you to override this default. See QGuiApplication 了解更多细节。

Writing a QPA plugin

There is no detailed tutorial documentation for writing QPA plugins at this time. However, there are two minimal plugins shipped with Qt for testing and other special purposes that you can use as examples:

  • qtbase/src/plugins/platforms/minimal/
  • qtbase/src/plugins/platforms/minimalegl/

The qminimal 插件是工具用于链接到 Qt GUI ,但不要求窗口系统集成 (例如, qmlplugindump )。它还拥有诊断支持,可以通过环境变量确定把窗口内容转储到图像文件。