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) 支持

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 了解更多细节。

编写 QPA 插件

目前还没有编写 QPA 插件的详细教程文档编制。不管怎样,Qt 随附 2 个用于测试及其它特殊目的的最小插件,可以用作范例:

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

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