What is the proper way to use the QCamera API?

asked 2016-06-14 16:59:37 +0300

Fiery gravatar image

updated 2018-12-03 21:35:48 +0300

Tanghus gravatar image

I'm trying to detect the available cameras in the device, and get some basic properties of them, like still image resolution (which should equal to image sensor resolution), video recording resolution, presence of LED flash, etc. I'm trying QT calls from C++ code like this:

QCameraInfo::defaultCamera().deviceName()

QList<QCameraInfo> cameras = QCameraInfo::availableCameras();

QList<QByteArray> devices = QCamera::availableDevices();

It doesn't seem to work at all on the Jolla Phone, it runs very slowly and causes the app to hang for seconds. And it returns 9 camera devices, from /dev/video0 through /dev/video8 on the Jolla Tablet, which is even more strange. What am I doing wrong?

edit retag flag offensive close delete

Comments

proper way is qml

coderus ( 2016-06-14 19:07:06 +0300 )edit
1

Thank you for the info. I'm quite surprised to hear about that. Based on the official QCamera doc ( doc.qt.io/qt-5/qcamera.html ) I assumed it would work equally fine in QML and C++. Is this a Sailfish OS platform limitation, or a platform bug? I'm just wondering because I can use for example Qt Sensors in both QML and C++ under SFOS, on both Jolla Phone and Jolla Tablet, so such limitation doesn't apply there as far as I can tell...

Fiery ( 2016-06-14 21:00:08 +0300 )edit

I've tried the QML way, but it acts similarly bad as the C++ way. Here's the code that fails to work:

import QtMultimedia 5.4

    Page {
        property int    availCam: QtMultimedia.availableCameras.length
    }

It takes a long time to return 0 as length, just like under C++. Maybe the QCamera implemenation in SFOS cannot provide the list of available cameras at all? If so, then how can I detect the presence of cameras, and how to select the front or rear camera, to let me then detect its capabilities?

Fiery ( 2016-06-15 09:55:11 +0300 )edit