Qt Extras 模块的变更
Qt 6 是为了使该框架更高效、更易于使用而付出的有意识努力的结果。
我们力求在每个版本中保持所有公共 API 的二进制和源代码兼容性。但在努力使 Qt 成为更好的框架的过程中,某些变更在所难免。
其中一项变更就是移除了特定于平台的 Extras 模块,以确保 Qt 6 具有一致的跨平台体验和未来发展前景。这些模块提供的大部分功能已被其他 Qt 模块中的类似功能所取代。 本指南总结了这些替代方案,并针对 Qt 未提供替代 API 的情况提供了指导。
Qt Mac Extras 的变更
QtMac 命名空间
QtMac 命名空间中的大多数成员都有明确的替代方案。由于该 API 没有已知的客户端,QtMac::fromCGImageRef函数已被移除。
QMacPasteboardMime
QMacPasteboardMime类已被QUtiMimeConverter 取代。详情请参阅《Qt GUI 的变更》中的“原生剪贴板集成”部分。
QMacToolBar
QMacToolBar和QMacToolBarItem类已被移除。请使用QToolBar 作为替代。
Qt Windows Extras 的变更
QtWin 命名空间
QtWin 命名空间中的许多成员都有明确的替代方案。若要在Qt Widgets 或Qt Quick 中使用这些替代方案,请对相关小部件或控件的QWindow 表示形式进行操作。
其余函数已被移除:
errorStringFromHresult
仅在 WinExtras 内部使用。目前未发现其他使用该 API 的客户端。
colorizationColor/isCompositionOpaque
该概念在其他平台上已存在(色调/强调色)。应为此创建新的跨平台 API,例如新的QPalette 角色或平台主题属性。
setWindowFlip3DPolicy
Windows 7 功能。在 Windows 10 中已不再受支持。
extendFrameIntoClientArea
其他平台也存在类似功能。应提供跨平台的QWindow API,以控制客户端区域与非客户端区域(框架/标题栏)之间的关系。详情请参阅QTBUG-94010。
enableBlurBehind
自 Windows 8 起已弃用。
taskbarActivateTab 和 taskbar(Add/Delete)Tab
目前尚无已知的该 API 客户端。
QWinMime
QWinMime类已被QWindowsMimeConverter 取代。详情请参阅《Qt GUI 的变更 #本机剪贴板集成》。
QWinJumpList
由于需要采用跨平台解决方案,QWinJumpList、QWinJumpListCategory 和QWinJumpListItem类已被移除。详情请参阅QTBUG-94007。
QWinTaskbarButton
由于需要采用跨平台解决方案,已移除QWinTaskbarButton和QWinTaskbarProgress类。详情请参阅QTBUG-94009和QTBUG-94008。
QWinThumbnailToolBar
由于该 API 没有已知的客户端,因此已移除QWinThumbnailToolBar和QWinThumbnailToolButton类。
Qt X11 Extras 的变更
Qt 6 中已移除了Qt X11 Extras模块。
- 对于 QX11Info::connection(),请改用QNativeInterface::QX11Application::connection()。
- 对于 QX11Info::display(),请改用QNativeInterface::QX11Application::display()。
- 对于 QX11Info::isPlatformX11(),请改为检查QNativeInterface::QX11Application 是否存在。
请务必确认能够从QGuiApplication 获取QNativeInterface::QX11Application 对象,如下面的代码片段所示:
Display *display = nullptr;
xcb_connection_t *connection = nullptr;
bool isPlatformX11 = false;
if (auto *x11Application = qGuiApp->nativeInterface<QNativeInterface::QX11Application>()) {
display = x11Application->display();
connection = x11Application->connection();
isPlatformX11 = true;
}
// or
// isPlatformX11 = qGuiApp->nativeInterface<QNativeInterface::QX11Application>();仍依赖QX11Info类功能的客户端可将私有头文件<QtGui/private/qtx11extras_p.h> 作为临时解决方案引入。要启用私有头文件,请将QT += gui-private 与qmake 结合使用,或通过CMake 向项目添加对Qt::GuiPrivate 的依赖。
Qt for Android Extras 的变更
该模块的关键功能已迁移至其他 Qt 模块。
仍依赖于已缺失功能的客户端,可将私有头文件<QtCore/private/qandroidextras_p.h> 作为临时解决方案。要启用私有头文件,请使用QT += core-private 并访问qmake ,或通过CMake 将Qt::CorePrivate 添加为项目依赖项。
QAndroidJniObject 和 QAndroidJniEnvironment
QAndroidJniObject和QAndroidJniEnvironment类已分别被QJniObject 和QJniEnvironment 所取代。
QAndroidJniExceptionCleaner类已不再需要。请参阅QJniEnvironment::checkAndClearExceptions() 以了解替代方案。
QtAndroid 命名空间
QtAndroid 命名空间中的许多成员在QAndroidApplication 本机接口中都有对应的替代实现。
权限
应用程序权限基础设施允许以跨平台的方式请求一组权限。
QtAndroidPrivate 命名空间可用于访问跨平台权限系统未涵盖的 Android 特定权限。
© 2026 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.