How to start stop QCamera?

362 Views Asked by At
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include "unistd.h"
#include <qdebug.h>
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
m_scene = new QGraphicsScene;
m_item = new QGraphicsVideoItem;

ui->graphicsView->setScene(m_scene);
ui->graphicsView->scene()->addItem(m_item);

camera = new QCamera(QCameraInfo::defaultCamera());
camera->setViewfinder(m_item);
camera->setCaptureMode(QCamera::CaptureVideo);
}

MainWindow::~MainWindow()
{
delete ui;
}
// On Start Button
void MainWindow::on_pushButton_clicked()
{
camera->start();
}
// On Stop Button
void MainWindow::on_pushButton_2_clicked()
{
camera->stop();
}

I have above code to stream USB camera. Camera stream does not start on pressing "Start Button". Camera stream is displayed when I first press stop button and then start button.

I can not understand this behaviour. How to make it work correctly?

0

There are 0 best solutions below