Connecting to the camera
Here comes the most exciting part. We are going to learn how to access our camera(s) using Qt's multimedia module! First, open mainwindow.h
and add the following headers:
#include <QMainWindow> #include <QDebug> #include <QCameraInfo> #include <QCamera> #include <QCameraViewfinder> #include <QCameraImageCapture> #include <QMediaRecorder> #include <QUrl>
Next, add the following variable, as shown here:
private:
Ui::MainWindow *ui;
QCamera* camera;
QCameraViewfinder* viewfinder;
bool connected;
Then, open up mainwindow.cpp
and add the following code to the class constructor to initiate the QCamera
object. We then use the QCameraInfo
class to retrieve a list of connected cameras and fill in that information in the combo box widget:
MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow) { ui->setupUi(this); connected = false; camera = new QCamera...