0
votes

Ok, so I am using Blackberry 10 Cascades (QT, QML, C++), and I am trying to process photos that get taken by the camera. I have been looking into how to do this on the internet, and figured out some things, but it's not working yet. Here's what I have done (I have made a point to highlight the most relevant parts of the code with //---------------RELEVANT LINE(S) OF CODE--------------------------------- to begin and //------------------------------------------------------------------------ to end the relevant sections.

//Camera.h

#ifndef CAMERA_H_
#define CAMERA_H_

#include <QObject>
#include <Page.h>


namespace bb {
    namespace cascades {
        class Container;
        namespace multimedia {
            class Camera;
        }
    }
}

namespace GDLiteBB {

    class Camera : public QObject, public Page_ {
        Q_OBJECT

        //-----------------RELEVANT LINE OF CODE---------------------
        bb::cascades::multimedia::Camera *cameraDevice_;
        //-----------------------------------------------------------

        static Camera *Camera_;

        Camera(
            QString *qmlFileName = new QString(""),
            QString *qmlVarName = new QString(""),
            QObject *parent = 0);

    public:

        static Camera *getInstance(
            QString *qmlFileName = new QString("main.qml"),
            QString *qmlVarName = new QString("camera"),
            QObject *parent = 0);

        virtual ~Camera();

    Camera *show(bb::cascades::Container *container = 0);

    void showCamera();

        //-----------------RELEVANT LINES OF CODE---------------------
        public slots:
        void onPhotoSaved(const QString &fileName, quint64 length);
       //-------------------------------------------------------------
};

} /* namespace GDLiteBB */

#endif /* CAMERA_H_ */

//Camera.cpp

Camera::Camera(
    QString *qmlFileName,
    QString *qmlVarName,
    QObject *parent)
: QObject(parent),
    Page_(qmlFileName, qmlVarName) 
{
    INIT_PAGE

    if (Root_) {
        //-----------------RELEVANT LINES OF CODE---------------------
        cameraDevice_ =
            Root_->findChild<bb::cascades::multimedia::Camera *>("camera1");

        connect(cameraDevice_, SIGNAL(photoSaved(const QString&, quint64)), this,
            SLOT(onPhotoSaved(const QString&, quint64)));
       //----------------------------------------------------------------

    } else {
        cameraDevice_ = 0;
    }
}

//-----------------RELEVANT LINES OF CODE---------------------
void Camera::onPhotoSaved(
    const QString &fileName,
    quint64 length)
{
    disconnect(
        cameraDevice_,
        SIGNAL(photoSaved(const QString&, quint64)),
        this,
        SLOT(onPhotoSaved(const QString&, quint64)));

    qDebug() << "onPhotoSaved";
    qDebug() << "filename is " << fileName << ", length is " << length << "test";
}
//-----------------------------------------------------------------

But when I take a picture, the onPhotoSaved slot is not being triggered, for the qDebug is not happening.

I know that the photo is being saved tho, because in the qml, I have:

Label {
    id: cameraDebug
}
Camera {
    ...
    onPhotoSaved: {
        photoBeingTaken = false;
        cameraDebug.text = "saved photo"
    } 
}

and the label, cameraDebug, changes to "saved photo", after taking a photo., so I am catching the QML signal for saved photo, but I need to catch the C++ signal for saved photo, because I need the filename of the photo, and that is not working, as I said above.

1

1 Answers

1
votes

I figured out the problem. The line:

cameraDevice_ = Root_->findChild<bb::cascades::multimedia::Camera *>("camera1");

was assinging null, because there was no actual "objectName: camera1" in the qml code, there was only "id: camera1", therefore, there was no way to connect cameraDevice_ to the onPhotoSaved slot, since it was null.

It was a silly bug, but I hope this question and answer might benefit others who are looking to figure out how to process a saved photo in blackberry cascades, or just handle signals and slots in general in QT, or how ever else it might help them.