What is this QML code doing?



  • Hello All,

    I'm working on a mobile platform (Android) and trying to access the camera via the C++ Multimedia classes like QCamera. However, I only have success opening my device's camera when I use the declarative-camera example, which uses a QML script. As far as I can tell, the code needed to display incoming frames in a viewfinder is

    @VideoOutput {
    id: video
    anchors.fill: parent
    source: camera

        Camera {
            id: camera
        }
    }@
    

    I was wondering if anyone knew how to translate this code to c++; I tried the following, but I'm having no luck:

    @int main(int argc, char *argv[])
    {
    QApplication a(argc, argv);

    QCamera * camera;
    QCameraViewfinder * viewFinder;
    
    QList<QCameraInfo> cameras = QCameraInfo::availableCameras();
    foreach (const QCameraInfo &cameraInfo, cameras) {
        qDebug() << cameraInfo.deviceName();
        // I know the "front" camera exists
        if (cameraInfo.deviceName() == "front"){
            camera = new QCamera(cameraInfo);
            qDebug() << "added the front camera";
        }
    }
    
    viewFinder = new QCameraViewfinder;
    camera->setViewfinder(viewFinder);
    
    viewFinder->show();
    viewFinder->resize(640,480);
    
    camera->start();
    
    return a.exec&#40;&#41;;
    

    }@

    Are there any other steps I need to take? The QML code specifies much less, but it actually works, so I was a bit confused.



  • There are some issues grabbing frames on Android which are discussed in the thread http://qt-project.org/forums/viewthread/35116/ and towards the end I include some code for setting up and starting the camera which may help you. The code generates a QImage for each frame, so its up to you how you display it.

    Good luck!



  • Thank you, that is helpful. I did end up going with a QVideoProbe based solution, but it seems like your solution gets around using QML (which is something I'd like to do.)

    edit:
    Can you elaborate a bit on what setting SuppressVideo does in the code? I'd just like to verify that you're using your own QAbstractVideoSurface in conjunction with the QVideoProbe and QCamera. I've tried something similar, but I never know if I'm implementing the abstract class correctly.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.