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 )。它還擁有診斷支持,可以通過環境變量確定把窗口內容轉儲到圖像文件。