summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorJøger Hansegård <joger.hansegard@qt.io>2023-12-12 14:46:06 +0100
committerQt Cherry-pick Bot <cherrypick_bot@qt-project.org>2023-12-14 12:50:50 +0000
commit522b7d56bad00334ec250c6334833fa9bcfdc8ec (patch)
treed6f04b6caad7fdbb86d75e957d7914ec9283e686 /src
parent8ae4ada251553dee55704f95a93e4ab7265b5bc6 (diff)
Move QMediaDevices example to manual tests and improve documentation
The Devices example is too simple to have as a full fledged example, and can better be expressed through snippets. Therefore, this patch moves the Devices example to manual tests, and improves the QMediaDevices doc by adding some snippets. Task-number: QTBUG-119117 Pick-to: 6.6 6.5 Change-Id: Id7c61e4f1b1047b73bae7e0619cf6238a30b8320 Reviewed-by: Artem Dyomin <artem.dyomin@qt.io> (cherry picked from commit 07622ff806324b5d5cf1e208c2110eb193f22103) Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
Diffstat (limited to 'src')
-rw-r--r--src/multimedia/doc/snippets/multimedia-snippets/devices.cpp38
-rw-r--r--src/multimedia/qmediadevices.cpp13
2 files changed, 51 insertions, 0 deletions
diff --git a/src/multimedia/doc/snippets/multimedia-snippets/devices.cpp b/src/multimedia/doc/snippets/multimedia-snippets/devices.cpp
new file mode 100644
index 000000000..652400364
--- /dev/null
+++ b/src/multimedia/doc/snippets/multimedia-snippets/devices.cpp
@@ -0,0 +1,38 @@
+// Copyright (C) 2023 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
+
+#include <QAudioDevice>
+#include <QCameraDevice>
+#include <QMediaDevices>
+#include <QString>
+#include <QTextStream>
+
+int main(int argc, char *argv[])
+{
+ Q_UNUSED(argc);
+ Q_UNUSED(argv);
+
+ QTextStream out(stdout);
+
+ //! [Media Audio Input Device Enumeration]
+ const QList<QAudioDevice> audioDevices = QMediaDevices::audioInputs();
+ for (const QAudioDevice &device : audioDevices)
+ {
+ out << "ID: " << device.id() << Qt::endl;
+ out << "Description: " << device.description() << Qt::endl;
+ out << "Is default: " << (device.isDefault() ? "Yes" : "No") << Qt::endl;
+ }
+ //! [Media Audio Input Device Enumeration]
+
+ //! [Media Video Input Device Enumeration]
+ const QList<QCameraDevice> videoDevices = QMediaDevices::videoInputs();
+ for (const QCameraDevice &device : videoDevices)
+ {
+ out << "ID: " << device.id() << Qt::endl;
+ out << "Description: " << device.description() << Qt::endl;
+ out << "Is default: " << (device.isDefault() ? "Yes" : "No") << Qt::endl;
+ }
+ //! [Media Video Input Device Enumeration]
+
+ return 0;
+}
diff --git a/src/multimedia/qmediadevices.cpp b/src/multimedia/qmediadevices.cpp
index 3f37d85a8..fa6f8630e 100644
--- a/src/multimedia/qmediadevices.cpp
+++ b/src/multimedia/qmediadevices.cpp
@@ -30,6 +30,19 @@ QT_BEGIN_NAMESPACE
from the system, it will update the corresponding device list and emit a signal
notifying about the change.
+ The QMediaDevices::audioInputs and QMediaDevices::audioOutputs functions can be used
+ to enumerate all microphones and speakers/headsets on the system. This example first
+ gets a list of all connected microphones, and then prints their identifier, description,
+ and if it is the default device or not.
+
+ \snippet multimedia-snippets/devices.cpp Media Audio Input Device Enumeration
+
+ Similarly, the QMediaDevices::videoInputs will return a list of all connected cameras.
+ In this example we list all connected cameras and their identifier, description, and
+ if it is the default camera or not.
+
+ \snippet multimedia-snippets/devices.cpp Media Video Input Device Enumeration
+
QMediaDevices monitors the system defaults for each device group. It will notify about
any changes done through the system settings. For example, if the user selects a new
default audio output in the system settings, QMediaDevices will update the default audio