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.)
This commit is contained in:
Rayyan Ansari 2023-11-05 15:40:48 +00:00
parent 0aff9471c5
commit df571078cf
No known key found for this signature in database
GPG Key ID: 46A8D18E5BC49D84
1 changed files with 8 additions and 0 deletions

View File

@ -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;