Qt 平台抽象
Qt 平台抽象(QPA)是 Qt 的主要平台抽象层。
该 API 可通过QPlatform*
类前缀识别,用于实现更高级别的类,通常可在以下网站找到 Qt GUI例如,通过QPlatformWindow
实现窗口系统集成,通过QWindow 实现窗口系统集成,或通过QPlatformTheme
实现更深层次的平台主题化和集成,通过 QStyleHint 和QStyle 实现平台主题化和集成。
QPA 类没有源代码或二进制兼容性保证,这意味着 API 只能保证与开发时所使用的 Qt 版本兼容。不过,只有在次要版本中才会对 API 进行修改。(5.1、5.2 等)。
API 概述
- 窗口系统集成
- QPlatformIntegration
- QPlatformAccessibility
- QPlatformBackingStore
- 平台剪贴板
- QPlatformCursor
- QPlatformDrag
- QPlatformFontDatabase
- QPlatformGraphicsBuffer
- QPlatformInputContext
- QPlatformOffscreenSurface
- QPlatformOpenGLContext
- QPlatformScreen
- QPlatformServices
- QPlatformSharedGraphicsCache
- QPlatformSurface
- QPlatformWindow
- 风格/主题
- 平台主题
- 平台调色板
- 平台字体
- 主题提示
- 本地对话框和菜单
- QPlatformDialogHelper
- 平台菜单
- QPlatformMenuBar
- QPlatformMenuItem
注意: 除了 QPA API 之外,Qt 中还有许多其他平台抽象,例如,Qt 中的事件派发器抽象和 RHI 中的渲染硬件抽象。 Qt Core中的事件派发器抽象和 RHI 中的渲染硬件抽象。QPA API 主要侧重于窗口系统集成和相关支持。
QPA 插件
上述接口的具体实现在 QPA 插件或平台插件中,为 Qt 运行的各种平台添加支持。QPA 插件通过子类化QPlatform*
类来实现。
下表总结了可用的平台插件:
插件名称 | 插件类名称 | 描述 |
---|---|---|
qandroid | QAndroid 平台集成 | 支持安卓 |
qbsdfb | QBsdFb 集成 | 支持 BsdFb |
qcocoa | QCocoaIntegrationPlugin | macOS 支持 |
qdirect2d | QWindowsDirect2DIntegration 插件 | 与qwindows 插件类似,但将光栅绘制引擎替换为基于 Direct2D 的绘制引擎,适用于QPixmap 和QBackingStore 。 |
qdirectfb | QDirectFB 集成插件 | DirectFB 以曲面为中心,相当于QPaintDevice 。 |
qeglfs | QEglFSIntegrationPlugin | 为嵌入式 Linux 设备提供EGLFS支持。 |
qhaiku | QHaikuIntegration | 俳句支持 |
qios | QIOSIntegrationPlugin | iOS 支持 |
qlinuxfb | QLinuxFbIntegrationPlugin | 为嵌入式 Linux 设备提供LinuxFB支持。 |
qvnc | QVncIntegration | 支持 VNC |
qwayland |
| Wayland 支持 |
qwindows | QWindowsIntegrationPlugin | Windows 支持 |
qxcb | QXcbIntegrationPlugin | 支持 X 窗口系统 (X11) |
选择 QPA 插件
Qt 将根据平台选择默认的 QPA 插件。QT_QPA_PLATFORM
环境变量和-platform
命令行参数允许您覆盖默认值。详情请参阅QGuiApplication 。
编写 QPA 插件
目前还没有编写 QPA 插件的详细教程文档。不过,Qt 提供了两个用于测试和其他特殊用途的最小插件,您可以将其作为示例:
qtbase/src/plugins/platforms/minimal/
qtbase/src/plugins/platforms/minimalegl/
qminimal
插件用于链接到 Qt GUI但不需要与窗口系统集成的工具(例如qmlplugindump
)。它还提供诊断支持,可根据环境变量将窗口内容转储到镜像文件中。
© 2025 The Qt Company Ltd. Documentation contributions included herein are the copyrights of their respective owners. The documentation provided herein is licensed under the terms of the GNU Free Documentation License version 1.3 as published by the Free Software Foundation. Qt and respective logos are trademarks of The Qt Company Ltd. in Finland and/or other countries worldwide. All other trademarks are property of their respective owners.