A preview windows shows something from the camera.
authorPhilipp Spitzer <philipp@spitzer.priv.at>
Wed, 21 Jun 2017 20:26:25 +0000 (22:26 +0200)
committerPhilipp Spitzer <philipp@spitzer.priv.at>
Wed, 21 Jun 2017 20:26:25 +0000 (22:26 +0200)
qtapp/barcode2cash/barcode2cash.pro
qtapp/barcode2cash/mainwindow.cpp

index 11c90e6365eac252ea88a4c1ec6f3447d82c836f..d4399f50b91f2f4bf6f546b7eb68b0976023349c 100644 (file)
@@ -4,7 +4,7 @@
 #
 #-------------------------------------------------
 
-QT       += core gui multimedia
+QT       += core gui multimedia multimediawidgets
 
 greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
 
index 4fe6b38ab6a561cfeed72374e5f0ab6c87b44e3c..94285c256edeb20f2b3d86cd77e869aed2fd333a 100644 (file)
@@ -1,6 +1,8 @@
 #include "mainwindow.h"
 #include "ui_mainwindow.h"
 #include <QCameraInfo>
+#include <QCameraImageCapture>
+#include <QCameraViewfinder>
 
 bool checkCameraAvailability()
 {
@@ -16,6 +18,21 @@ MainWindow::MainWindow(QWidget *parent) :
 {
     ui->setupUi(this);
 
+    QCameraInfo info = QCameraInfo::defaultCamera();
+    if (!info.isNull()) {
+        QCamera* camera = new QCamera(info);
+        camera->setCaptureMode(QCamera::CaptureStillImage);
+        QCameraViewfinder* viewfinder = new QCameraViewfinder;
+        camera->setViewfinder(viewfinder);
+        viewfinder->show();
+        QCameraImageCapture imageCapture(camera);
+        camera->start();
+        camera->searchAndLock();
+        imageCapture.capture("test.png");
+        camera->unlock();
+        //delete camera;
+    }
+
     ui->statusBar->showMessage(tr("There are %1 cameras").arg(checkCameraAvailability()));
 }