int main(int argc, char *argv[]) { QCoreApplication a(argc, argv); QList<QByteArray> devices = QCamera::availableDevices(); // QGPhotoServicePlugin s; // devices = s.devices(Q_MEDIASERVICE_CAMERA); for (QList<QByteArray>::Iterator i = devices.begin(); i != devices.end(); i ++) { QByteArray current = *i; cout << QString(current).toStdString() << "\n"; } cout << "### New camera\n"; cout.flush(); QCamera *camera = new QCamera(devices[1]); cout << "### Camera device description\n"; cout.flush(); QString description = camera->deviceDescription(devices.at(1)); // std::cout << description.toStdString() << "\n"; QCameraImageCapture *imageCapture = new QCameraImageCapture(camera); // Object to take pictures camera->setCaptureMode(QCamera::CaptureStillImage); // Set the camera mode cout << "### Start camera\n"; cout.flush(); camera->start(); /* camera->searchAndLock(); imageCapture->capture(QString('/tmp/test.jpg')); // Method to take a picture. Arg: path to save the picture camera->unlock(); */ // imageCapture->capture(QString("/tmp/capture.nef")); qDebug() << camera->exposure()->supportedApertures(); qDebug() << camera->exposure()->supportedIsoSensitivities(); qDebug() << camera->exposure()->supportedShutterSpeeds(); qDebug() << "Aperture = " << camera->exposure()->aperture(); qDebug() << "Shutter speed = " << camera->exposure()->shutterSpeed(); qDebug() << "ISO = " << camera->exposure()->isoSensitivity(); camera->exposure()->setManualAperture(5.6); camera->exposure()->setManualShutterSpeed(10.0); camera->exposure()->setManualIsoSensitivity(800); cout << "### Stop camera\n"; cout.flush(); camera->stop(); delete imageCapture; delete camera; return a.exec(); }
void tst_QCameraBackend::testCaptureMode() { QCamera camera; QSignalSpy errorSignal(&camera, SIGNAL(error(QCamera::Error))); QSignalSpy stateChangedSignal(&camera, SIGNAL(stateChanged(QCamera::State))); QSignalSpy captureModeSignal(&camera, SIGNAL(captureModeChanged(QCamera::CaptureModes))); QCOMPARE(camera.captureMode(), QCamera::CaptureStillImage); if (!camera.isCaptureModeSupported(QCamera::CaptureVideo)) { camera.setCaptureMode(QCamera::CaptureVideo); QCOMPARE(camera.captureMode(), QCamera::CaptureStillImage); QSKIP("Video capture not supported"); } camera.setCaptureMode(QCamera::CaptureVideo); QCOMPARE(camera.captureMode(), QCamera::CaptureVideo); QTRY_COMPARE(captureModeSignal.size(), 1); QCOMPARE(captureModeSignal.last().first().value<QCamera::CaptureModes>(), QCamera::CaptureVideo); captureModeSignal.clear(); camera.load(); QTRY_COMPARE(camera.status(), QCamera::LoadedStatus); //capture mode should still be video QCOMPARE(camera.captureMode(), QCamera::CaptureVideo); //it should be possible to switch capture mode in Loaded state camera.setCaptureMode(QCamera::CaptureStillImage); QTRY_COMPARE(captureModeSignal.size(), 1); QCOMPARE(captureModeSignal.last().first().value<QCamera::CaptureModes>(), QCamera::CaptureStillImage); captureModeSignal.clear(); camera.setCaptureMode(QCamera::CaptureVideo); QTRY_COMPARE(captureModeSignal.size(), 1); QCOMPARE(captureModeSignal.last().first().value<QCamera::CaptureModes>(), QCamera::CaptureVideo); captureModeSignal.clear(); camera.start(); QTRY_COMPARE(camera.status(), QCamera::ActiveStatus); //capture mode should still be video QCOMPARE(camera.captureMode(), QCamera::CaptureVideo); stateChangedSignal.clear(); //it should be possible to switch capture mode in Active state camera.setCaptureMode(QCamera::CaptureStillImage); //camera may leave Active status, but should return to Active QTest::qWait(10); //camera may leave Active status async QTRY_COMPARE(camera.status(), QCamera::ActiveStatus); QCOMPARE(camera.captureMode(), QCamera::CaptureStillImage); QVERIFY2(stateChangedSignal.isEmpty(), "camera should not change the state during capture mode changes"); QCOMPARE(captureModeSignal.size(), 1); QCOMPARE(captureModeSignal.last().first().value<QCamera::CaptureModes>(), QCamera::CaptureStillImage); captureModeSignal.clear(); camera.setCaptureMode(QCamera::CaptureVideo); //camera may leave Active status, but should return to Active QTest::qWait(10); //camera may leave Active status async QTRY_COMPARE(camera.status(), QCamera::ActiveStatus); QCOMPARE(camera.captureMode(), QCamera::CaptureVideo); QVERIFY2(stateChangedSignal.isEmpty(), "camera should not change the state during capture mode changes"); QCOMPARE(captureModeSignal.size(), 1); QCOMPARE(captureModeSignal.last().first().value<QCamera::CaptureModes>(), QCamera::CaptureVideo); captureModeSignal.clear(); camera.stop(); QCOMPARE(camera.captureMode(), QCamera::CaptureVideo); camera.unload(); QCOMPARE(camera.captureMode(), QCamera::CaptureVideo); QVERIFY2(errorSignal.isEmpty(), QString("Camera error: %1").arg(camera.errorString()).toLocal8Bit()); }