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
    {
    Q_OBJECT

    public:
    Camera2();

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

    private:
    QCamera* pCamera;
    QCameraImageCapture* pCapture;
    };
    @

    File camera.cpp
    @
    void Camera2::test()
    {
    pCamera=new QCamera();
    pCapture=new QCameraImageCapture(pCamera);
    pCamera->setViewfinder(new QCameraViewfinder());
    connect(pCapture,SIGNAL(imageCaptured(int,QImage)),this,SLOT(imageCaptured(int,QImage)));
    pCamera->setCaptureMode(QCamera::CaptureStillImage);
    pCamera->load();
    pCamera->start();
    QTimer::singleShot(10000,pCapture,SLOT(capture()));
    }

    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
 

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