QScreenCapture Class

The QScreenCapture class is used for capturing a screen view or a window view. More...

Header: #include <QScreenCapture>
CMake: find_package(Qt6 REQUIRED COMPONENTS Multimedia)
target_link_libraries(mytarget PRIVATE Qt6::Multimedia)
qmake: QT += multimedia
Instantiated By: ScreenCapture
Inherits: QObject

Public Types

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

Properties

Public Functions

QMediaCaptureSession *captureSession() const
QScreenCapture::Error error() const
QString errorString() const
bool isActive() const
QScreen *screen() const
void setScreen(QScreen *screen)
void setWindow(QWindow *window)
void setWindowId(WId id)
QWindow *window() const
WId windowId() const

Public Slots

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

Signals

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

Detailed Description

The class captures a screen view or window view. It is managed by the QMediaCaptureSession class where the captured view can be displayed in a window 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();

Member Type Documentation

enum QScreenCapture::Error

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

ConstantValueDescription
QScreenCapture::NoError0No error
QScreenCapture::InternalError1Internal screen capturing driver error
QScreenCapture::CapturingNotSupported2Capturing is not supported
QScreenCapture::WindowCapturingNotSupported3Window capturing is not supported
QScreenCapture::CaptureFailed4Capturing screen or window view failed
QScreenCapture::NotFound5Selected screen or window not found

Property Documentation

active : bool

Describes whether the capturing is currently active.

Access functions:

bool isActive() const
void setActive(bool active)

Notifier signal:

void activeChanged(bool)

[read-only] error : const Error

Returns a code of the last error.

Access functions:

QScreenCapture::Error error() const

Notifier signal:

void errorChanged()

[read-only] errorString : const QString

Returns a human readable string describing the cause of error.

Access functions:

QString errorString() const

Notifier signal:

void errorChanged()

screen : QScreen*

Describes the screen for capturing.

Access functions:

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

Notifier signal:

void screenChanged(QScreen *)

window : QWindow*

Describes the window for capturing.

Access functions:

QWindow *window() const
void setWindow(QWindow *window)

Notifier signal:

void windowChanged(QWindow *)

windowId : WId

Describes the window ID for capturing.

Access functions:

WId windowId() const
void setWindowId(WId id)

Notifier signal:

void windowIdChanged(WId)

Member Function Documentation

QMediaCaptureSession *QScreenCapture::captureSession() const

Returns the capture session this QScreenCapture is connected to.

Use 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()

Starts screen capture.

[slot] void QScreenCapture::stop()

Stops screen capture.