ScreenCapture QML Type

该类型用于捕捉屏幕。更多

Import Statement: import QtMultimedia
Since: Qt 6.5
In C++: QScreenCapture

属性

详细说明

ScreenCapture 可捕获屏幕。它由 MediaCaptureSession 管理,捕获的屏幕可显示在视频预览对象中或录制到文件中。

下面的代码显示了一个简单的捕获会话,ScreenCapture 会在VideoOutput 中播放捕获的主屏幕视图。

CaptureSession {
    id: captureSession
    screenCapture: ScreenCapture {
        id: screenCapture
        active: true
    }
    videoOutput: VideoOutput {
        id: videoOutput
    }
}

屏幕捕捉限制

在 Qt 6.5.2 及以上版本中,使用 ScreenCapture 有以下限制:

  • 仅支持 FFmpeg 后端。
  • 在使用 Wayland 合成器的 Linux 系统上,屏幕捕捉的实现是试验性的,有以下限制。由于 Wayland 协议的限制,无法通过QScreenCapture 类的 API 设置和获取目标屏幕。相反,操作系统会在调用QScreenCapture::setActive(true) 时显示屏幕选择向导。屏幕捕捉功能需要安装通过XDG Desktop Portal和 {https://pipewire.org/}{PipeWire} (0.3) 支持的ScreenCast服务。这些限制将来可能会改变。
  • 移动操作系统不支持该功能,安卓系统除外。安卓系统上的屏幕捕捉需要在AndroidManifest.xml 文件中添加额外的安卓前台服务权限
    <manifest ...>
    <uses-permission android:name="android.permission.FOREGROUND_SERVICE" />
    <uses-permission android:name="android.permission.FOREGROUND_SERVICE_MEDIA_PROJECTION" />
    <application ...>
        <service android:name="org.qtproject.qt.android.multimedia.QtScreenCaptureService"
            android:foregroundServiceType="mediaProjection"
            android:exported="false"/>
        </service>
    </application>
    </manifest>
  • 在使用 EGLFS 的嵌入式系统上,它的功能有限。对于Qt Quick 应用程序,该类目前是通过QQuickWindow::grabWindow 实现的,这可能会导致性能问题。
  • 在大多数情况下,我们设置的屏幕捕获帧频等于屏幕刷新率,但 Windows 系统除外,因为 Windows 系统的刷新率可能比较灵活。如果捕获的屏幕分辨率为 4K,这样的帧频(75/120 FPS)可能会对性能较弱的 CPU 造成性能问题。在 EGLFS 上,捕捉帧频目前锁定为 30 FPS。

另请参阅 WindowCaptureCaptureSession

属性文档

active : bool

描述当前捕捉是否激活。


error : enumeration [read-only]

返回上次错误的代码。


errorString : string [read-only]

返回描述错误原因的可读字符串。


screen : Screen

描述用于捕捉的屏幕。


© 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.