QScreenCapture 類

此類用於捕獲屏幕。 更多...

頭: #include <QScreenCapture>
CMake: find_package(Qt6 REQUIRED COMPONENTS Multimedia)
target_link_libraries(mytarget PRIVATE Qt6::Multimedia)
qmake: QT += multimedia
Since: Qt 6.5
在 QML: ScreenCapture
繼承: QObject

公共類型

enum Error { NoError, InternalError, CapturingNotSupported, CaptureFailed, NotFound }

特性

公共函數

QMediaCaptureSession * captureSession () const
QScreenCapture::Error error () const
QString errorString () const
bool isActive () const
QScreen * screen () const
void setScreen (QScreen * screen )

公共槽

void setActive (bool active )
void start ()
void stop ()

信號

void activeChanged (bool)
void errorChanged ()
void errorOccurred (QScreenCapture::Error error , const QString & errorString )
void screenChanged (QScreen *)

詳細描述

The class captures a screen. It is managed by the QMediaCaptureSession class where the captured screen can be displayed in a video preview object or recorded to a file.

QMediaCaptureSession session;
QAudioInput audioInput;
session.setAudioInput(&input);
QMediaRecorder recorder;
session.setRecorder(&recorder);
recorder.setQuality(QMediaRecorder::HighQuality);
recorder.setOutputLocation(QUrl::fromLocalFile("test.mp3"));
recorder.record();
					

屏幕捕獲局限性

On Qt 6.5.2 and above, the following limitations apply to using QScreenCapture:

  • It is only supported with the FFmpeg backend.
  • On Linux systems using the Wayland compositor, the screen capture implementation is experimental and comes with the following limitations. Due to restrictions of the Wayland protocol, it's impossible to set and get the target screen via the API of the QScreenCapture class. Instead, the OS will show a screen selection wizard upon invoking QScreenCapture::setActive(true) . The screen capture feature requires the installation of the ScreenCast service supported via XDG Desktop Portal and {https://pipewire.org/}{PipeWire} (0.3). These limitations might change in the future.
  • It is not supported on mobile operating systems, except on Android. Screen Capture on Android needs additional Android foreground service permission to be added to the 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>
    							
  • On embedded with EGLFS, it has limited functionality. For Qt Quick applications, the class is currently implemented via QQuickWindow::grabWindow , which can cause performance issues.
  • In most cases, we set a screen capture frame rate that equals the screen refresh rate, except on Windows, where the rate might be flexible. Such a frame rate (75/120 FPS) might cause performance issues on weak CPUs if the captured screen is of 4K resolution. On EGLFS, the capture frame rate is currently locked to 30 FPS.

另請參閱 QWindowCapture and QMediaCaptureSession .

成員類型文檔編製

enum QScreenCapture:: Error

Enumerates error codes that can be signaled by the QScreenCapture 類。 errorString () provides detailed information about the error cause.

常量 描述
QScreenCapture::NoError 0 沒有錯誤
QScreenCapture::InternalError 1 內部屏幕捕獲驅動程序錯誤
QScreenCapture::CapturingNotSupported 2 不支持捕獲
QScreenCapture::CaptureFailed 4 捕獲屏幕失敗
QScreenCapture::NotFound 5 找不到選中屏幕

特性文檔編製

active : bool

此特性保持捕獲目前是否活動。

訪問函數:

bool isActive () const
void setActive (bool active )

通知程序信號:

void activeChanged (bool)

[read-only] error : const Error

This property holds the code of the last error.

訪問函數:

QScreenCapture::Error error () const

通知程序信號:

void errorChanged ()

[read-only] errorString : const QString

This property holds a human readable string describing the cause of error.

訪問函數:

QString errorString () const

通知程序信號:

void errorChanged ()

screen : QScreen *

此特性保持用於捕獲的屏幕。

訪問函數:

QScreen * screen () const
void setScreen (QScreen * screen )

通知程序信號:

void screenChanged (QScreen *)

成員函數文檔編製

QMediaCaptureSession *QScreenCapture:: captureSession () const

Returns the capture session this QScreenCapture is connected to.

使用 QMediaCaptureSession::setScreenCapture () to connect the camera to a session.

[signal] void QScreenCapture:: errorOccurred ( QScreenCapture::Error error , const QString & errorString )

Signals when an error occurs, along with the errorString .

[slot] void QScreenCapture:: start ()

啓動屏幕捕獲。

[slot] void QScreenCapture:: stop ()

停止屏幕捕獲。