好的,所以我正在使用 Blackberry 10 Cascades(QT、QML、C++),并且我正在尝试处理相机拍摄的照片。我一直在寻找如何在互联网上做到这一点,并想出了一些东西,但它还没有奏效。这就是我所做的(我已经用 //---------------RELEVANT LINE(S) OF CODE----- 强调了代码中最相关的部分---------------------------- 开始和 //----------------- -------------------------------------------------- ----- 结束相关章节。
//相机.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_ */
//相机.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";
}
//-----------------------------------------------------------------
但是当我拍照时,onPhotoSaved 插槽没有被触发,因为 qDebug 没有发生。
我知道照片正在保存,因为在 qml 中,我有:
Label {
id: cameraDebug
}
Camera {
...
onPhotoSaved: {
photoBeingTaken = false;
cameraDebug.text = "saved photo"
}
}
并且标签cameraDebug在拍照后更改为“已保存的照片”,因此我正在捕获已保存照片的QML信号,但我需要捕获已保存照片的C++信号,因为我需要照片的文件名,这不起作用,正如我上面所说。