Qt Platform Abstraction

QPA (Qt 平颱抽象) 是 Qt 中的主要平颱抽象層。

API 可以被標識通過 QPlatform* 類前綴,且用於實現的更高級類,通常可找到在 Qt GUI ,如 QPlatformWindow 用於窗口係統集成,暴露透過 QWindow ,或 QPlatformTheme 用於深入平颱主題及集成,暴露透過 QStyleHint 和 QStyle .

QPA 類同有源代碼或二進製的兼容性保證,意味著 API 僅保證能工作於開發所針對的 Qt 版本。不管怎樣,API 改變隻在次要發行中進行 (如 5.1、5.2、依此類推)。

API 概述

  • 窗口係統集成
    • QPlatformIntegration
    • QPlatformAccessibility
    • QPlatformBackingStore
    • QPlatformClipboard
    • QPlatformCursor
    • QPlatformDrag
    • QPlatformFontDatabase
    • QPlatformGraphicsBuffer
    • QPlatformInputContext
    • QPlatformOffscreenSurface
    • QPlatformOpenGLContext
    • QPlatformScreen
    • QPlatformServices
    • QPlatformSharedGraphicsCache
    • QPlatformSurface
    • QPlatformWindow
  • 樣式/主題
    • QPlatformTheme
    • platform palettes
    • platform fonts
    • theme hints
  • 本機對話框和菜單
    • QPlatformDialogHelper
    • QPlatformMenu
    • QPlatformMenuBar
    • QPlatformMenuItem

注意: 除 QPA API 外,Qt 中還有很多其它平颱抽象,例如:事件調度程序抽象在 Qt Core 及 RHI 中的渲染硬件抽象。QPA API 多半聚焦在窗口係統集成及相關支持上。

QPA 插件

上文列齣的具體接口實現活在 QPA 插件或平颱插件中,從而增加對 Qt 運行的各平颱的支持。QPA 插件的實現是通過子類化 QPlatform* 類。

下錶匯總瞭可用的平颱插件:

插件名稱 插件類名 描述
qandroid QAndroidPlatformIntegration Android 支持
qbsdfb QBsdFbIntegration BsdFb 支持
qcocoa QCocoaIntegrationPlugin macOS 支持
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) 支持

選擇 QPA 插件

Qt 將根據平颱,選擇默認 QPA 插件。 QT_QPA_PLATFORM 環境變量和 -platform 命令行自變量允許覆寫此默認值。見 QGuiApplication 瞭解更多細節。

編寫 QPA 插件

目前還沒有編寫 QPA 插件的詳細教程文檔編製。不管怎樣,Qt 隨附 2 個用於測試及其它特殊目的最小插件,可以用作範例:

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

The qminimal 插件是工具用於鏈接到 Qt GUI ,但不要求窗口係統集成 (例如, qmlplugindump )。它還擁有診斷支持,可以通過環境變量確定把窗口內容轉儲到圖像文件。