我的代码如下。我已经对状态进行了多次检查,qDebug()在评论中显示了这一点。我真的无法弄清楚这是失败的原因。
QCamera *camera = new QCamera();
camera->setCaptureMode(QCamera::CaptureStillImage);
camera->load();
camera->start();
camera->searchAndLock();
QCameraImageCapture *imageCapture = new QCameraImageCapture(camera);
imageCapture->setCaptureDestination(QCameraImageCapture::CaptureToFile);
imageCapture->capture("~/test.jpg");
qDebug() << camera->state(); // QCamera::ActiveStatus
qDebug() << camera->status(); // QCamera::LoadedStatus
qDebug() << camera->isAvailable(); // true
qDebug() << camera->errorString(); // ""
qDebug() << imageCapture->isAvailable(); // true
qDebug() << imageCapture->errorString(); // "Camera not ready"
camera->unlock();
camera->stop();
答案 0 :(得分:1)
试试这个:
QCamera *camera;
QList<QByteArray> devices = QCamera::availableDevices();
if( devices.length()){
camera = new QCamera(devices.at(0));
}else{
qDebug() << "No camera found!";
}
必须使用有效设备初始化QCamera。