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:
parent
0aff9471c5
commit
df571078cf
|
@ -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;
|
||||
|
|
Loading…
Reference in New Issue