diff options
author | Rayyan Ansari <rayyan@ansari.sh> | 2023-11-05 15:40:48 +0000 |
---|---|---|
committer | Rayyan Ansari <rayyan@ansari.sh> | 2023-11-05 15:52:13 +0000 |
commit | df571078cfafcd0b98f3b84b84e44c97ac8ff7cf (patch) | |
tree | 5d6d86e49d6541f20aea8511f8a98615b3a9b9c8 | |
parent | 0aff9471c5a0f9f437e76cd9a7dd42312fc7968f (diff) |
CameraManager: wait for camera to be loaded
In QCamera in Qt 5, the camera is required to have been loaded before
querying its settings and resolutions. Doing so without loading being
finished would result in the returned list being empty.
See https://doc.qt.io/qt-5.15/qcamera.html#supportedViewfinderSettings
Add a QEventLoop that waits for the state to change from Loading to
Loaded before supportedViewfinderSettings() is called to ensure that
valid information is returned.
(Fixes my camera being blank in preview, same issue also presumed
to occur when camera is needed in game, fix tested on a USB camera on
a Linux system and Qt 5.)
-rw-r--r-- | src/frontend/qt_sdl/CameraManager.cpp | 8 |
1 files changed, 8 insertions, 0 deletions
diff --git a/src/frontend/qt_sdl/CameraManager.cpp b/src/frontend/qt_sdl/CameraManager.cpp index c158f5a..7f4db5d 100644 --- a/src/frontend/qt_sdl/CameraManager.cpp +++ b/src/frontend/qt_sdl/CameraManager.cpp @@ -16,6 +16,8 @@ with melonDS. If not, see http://www.gnu.org/licenses/. */ +#include <QEventLoop> + #include "CameraManager.h" #include "Config.h" @@ -256,6 +258,12 @@ void CameraManager::init() if (camDevice) { camDevice->load(); + if (camDevice->status() == QCamera::LoadingStatus) + { + QEventLoop loop; + connect(camDevice, &QCamera::statusChanged, &loop, &QEventLoop::quit); + loop.exec(); + } const QList<QCameraViewfinderSettings> supported = camDevice->supportedViewfinderSettings(); bool good = false; |