Qt World Summit: Register Today!

Camera based QML element

  • I am trying to create a configurable system to acquire and process still images of the (main) camera of an android device. The images are never intedended to be visible to the user, that is why I want to create my own QML element for the acquisition of raw data.
    While trying to implement that class (source below) I stumbled across the following problem:

    If I derive my Camera-class that uses an Instance of QCamera and QCameraImageCapture from QQuickItem, everything works fine on my labtop (windows 32bit kit), but it does not work on the android device. The callback that is supposed to process the image is never called und the application output states, that the camera issues error 1001 every few seconds. If I derive the camera-class from QMainWindow and call the show()-method before initialising the camera, it works fine. Right now I fail to see, why I would need a certain kind of user interface to be present in order to work the camera of the device. I would be grateful for any kind of advise.

    File camera.h
    class Camera2:public QMainWindow//public QQuickItem


    public slots:
    void test();
    void imageCaptured(int id, QImage img);

    QCamera* pCamera;
    QCameraImageCapture* pCapture;

    File camera.cpp
    void Camera2::test()
    pCamera=new QCamera();
    pCapture=new QCameraImageCapture(pCamera);
    pCamera->setViewfinder(new QCameraViewfinder());

    void Camera2::imageCaptured(int id, QImage img)
    QMessageBox::information(dynamic_cast<QWidget*>(this),"test",QString::number(img.height())+" x "+QString::number(img.width()), QMessageBox::Ok);

Log in to reply