Qt
Internal/Contributor docs for the Qt SDK. <b>Note:</b> These are NOT official API docs; those are found <a href='https://doc.qt.io/'>here</a>.
Loading...
Searching...
No Matches
qscreencapture.cpp
Go to the documentation of this file.
1// Copyright (C) 2022 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3
4#include "qscreencapture.h"
6#include <private/qplatformmediaintegration_p.h>
7#include <private/qplatformsurfacecapture_p.h>
8#include <private/qobject_p.h>
9
11
16
18{
19public:
21 std::unique_ptr<QPlatformSurfaceCapture> platformScreenCapture;
22};
23
79 : QObject(*new QScreenCapturePrivate, parent)
80{
81 Q_D(QScreenCapture);
82
83 auto platformCapture = QPlatformMediaIntegration::instance()->createScreenCapture(this);
84 if (platformCapture) {
85 connect(platformCapture, &QPlatformSurfaceCapture::activeChanged, this,
87 connect(platformCapture, &QPlatformSurfaceCapture::errorChanged, this,
89 connect(platformCapture, &QPlatformSurfaceCapture::errorOccurred, this,
92 });
93
94 connect(platformCapture,
95 qOverload<QPlatformSurfaceCapture::ScreenSource>(
98
99 d->platformScreenCapture.reset(platformCapture);
100 }
101}
102
104{
105 Q_D(QScreenCapture);
106
107 // Reset platformScreenCapture in the destructor to avoid having broken ref in the object.
108 d->platformScreenCapture.reset();
109
110 if (d->captureSession)
111 d->captureSession->setScreenCapture(nullptr);
112}
113
134{
135 Q_D(const QScreenCapture);
136
137 return d->captureSession;
138}
139
150{
151 Q_D(QScreenCapture);
152
153 if (d->platformScreenCapture)
154 d->platformScreenCapture->setActive(active);
155}
156
158{
159 Q_D(const QScreenCapture);
160
161 return d->platformScreenCapture && d->platformScreenCapture->isActive();
162}
163
175{
176 Q_D(QScreenCapture);
177
178 if (d->platformScreenCapture)
179 d->platformScreenCapture->setSource(QPlatformSurfaceCapture::ScreenSource(screen));
180}
181
183{
184 Q_D(const QScreenCapture);
185
186 return d->platformScreenCapture
187 ? d->platformScreenCapture->source<QPlatformSurfaceCapture::ScreenSource>()
188 : nullptr;
189}
190
201{
202 Q_D(const QScreenCapture);
203
204 return d->platformScreenCapture ? toScreenCaptureError(d->platformScreenCapture->error())
206}
207
223{
224 Q_D(const QScreenCapture);
225
226 return d->platformScreenCapture ? d->platformScreenCapture->errorString()
227 : QLatin1StringView("Capturing is not support on this platform");
228}
242void QScreenCapture::setCaptureSession(QMediaCaptureSession *captureSession)
243{
244 Q_D(QScreenCapture);
245
246 d->captureSession = captureSession;
247}
248
252class QPlatformSurfaceCapture *QScreenCapture::platformScreenCapture() const
253{
254 Q_D(const QScreenCapture);
255
256 return d->platformScreenCapture.get();
257}
258
260
261#include "moc_qscreencapture.cpp"
The QMediaCaptureSession class allows capturing of audio and video content.
\inmodule QtCore
Definition qobject.h:103
static QMetaObject::Connection connect(const QObject *sender, const char *signal, const QObject *receiver, const char *member, Qt::ConnectionType=Qt::AutoConnection)
\threadsafe
Definition qobject.cpp:2960
static QPlatformMediaIntegration * instance()
void errorOccurred(Error error, QString errorString)
void sourceChanged(WindowSource)
void activeChanged(bool)
std::unique_ptr< QPlatformSurfaceCapture > platformScreenCapture
QMediaCaptureSession * captureSession
\inmodule QtMultimedia
void setActive(bool active)
Error error
\qmlproperty enumeration QtMultimedia::ScreenCapture::error Returns a code of the last error.
void errorOccurred(QScreenCapture::Error error, const QString &errorString)
Signals when an error occurs, along with the errorString.
bool active
\qmlproperty bool QtMultimedia::ScreenCapture::active Describes whether the capturing is currently ac...
void screenChanged(QScreen *)
Error
Enumerates error codes that can be signaled by the QScreenCapture class.
void activeChanged(bool)
QScreenCapture(QObject *parent=nullptr)
QString errorString
\qmlproperty string QtMultimedia::ScreenCapture::errorString Returns a human readable string describi...
bool isActive() const
~QScreenCapture() override
QScreen * screen
\qmlproperty Screen QtMultimedia::ScreenCapture::screen Describes the screen for capturing.
void setScreen(QScreen *screen)
QMediaCaptureSession * captureSession() const
Returns the capture session this QScreenCapture is connected to.
void errorChanged()
The QScreen class is used to query screen properties. \inmodule QtGui.
Definition qscreen.h:32
\macro QT_RESTRICTED_CAST_FROM_ASCII
Definition qstring.h:129
Combined button and popup list for selecting options.
DBusConnection const char DBusError * error
static QT_BEGIN_NAMESPACE QScreenCapture::Error toScreenCaptureError(QPlatformSurfaceCapture::Error error)
QScreen * screen
[1]
Definition main.cpp:29
#define emit