Qt 6.x
The Qt SDK
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
13{
14 return static_cast<QScreenCapture::Error>(error);
15}
16
18{
19public:
21 std::unique_ptr<QPlatformSurfaceCapture> platformScreenCapture;
22};
23
74{
75 Q_D(QScreenCapture);
76
77 auto platformCapture = QPlatformMediaIntegration::instance()->createScreenCapture(this);
78 if (platformCapture) {
79 connect(platformCapture, &QPlatformSurfaceCapture::activeChanged, this,
81 connect(platformCapture, &QPlatformSurfaceCapture::errorChanged, this,
83 connect(platformCapture, &QPlatformSurfaceCapture::errorOccurred, this,
86 });
87
88 connect(platformCapture,
89 qOverload<QPlatformSurfaceCapture::ScreenSource>(
92
93 d->platformScreenCapture.reset(platformCapture);
94 }
95}
96
98{
99 Q_D(QScreenCapture);
100
101 // Reset platformScreenCapture in the destructor to avoid having broken ref in the object.
102 d->platformScreenCapture.reset();
103
104 if (d->captureSession)
105 d->captureSession->setScreenCapture(nullptr);
106}
107
128{
129 Q_D(const QScreenCapture);
130
131 return d->captureSession;
132}
133
144{
145 Q_D(QScreenCapture);
146
147 if (d->platformScreenCapture)
148 d->platformScreenCapture->setActive(active);
149}
150
152{
153 Q_D(const QScreenCapture);
154
155 return d->platformScreenCapture && d->platformScreenCapture->isActive();
156}
157
169{
170 Q_D(QScreenCapture);
171
172 if (d->platformScreenCapture)
173 d->platformScreenCapture->setSource(QPlatformSurfaceCapture::ScreenSource(screen));
174}
175
177{
178 Q_D(const QScreenCapture);
179
180 return d->platformScreenCapture
181 ? d->platformScreenCapture->source<QPlatformSurfaceCapture::ScreenSource>()
182 : nullptr;
183}
184
195{
196 Q_D(const QScreenCapture);
197
198 return d->platformScreenCapture ? toScreenCaptureError(d->platformScreenCapture->error())
200}
201
217{
218 Q_D(const QScreenCapture);
219
220 return d->platformScreenCapture ? d->platformScreenCapture->errorString()
221 : QLatin1StringView("Capturing is not support on this platform");
222}
236void QScreenCapture::setCaptureSession(QMediaCaptureSession *captureSession)
237{
238 Q_D(QScreenCapture);
239
240 d->captureSession = captureSession;
241}
242
246class QPlatformSurfaceCapture *QScreenCapture::platformScreenCapture() const
247{
248 Q_D(const QScreenCapture);
249
250 return d->platformScreenCapture.get();
251}
252
254
255#include "moc_qscreencapture.cpp"
The QMediaCaptureSession class allows capturing of audio and video content.
\inmodule QtCore
Definition qobject.h:90
static QMetaObject::Connection connect(const QObject *sender, const char *signal, const QObject *receiver, const char *member, Qt::ConnectionType=Qt::AutoConnection)
\threadsafe
Definition qobject.cpp:2823
static QPlatformMediaIntegration * instance()
virtual QPlatformSurfaceCapture * createScreenCapture(QScreenCapture *)
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 string 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:127
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
IUIAutomationTreeWalker __RPC__deref_out_opt IUIAutomationElement ** parent