#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();
}
我有上面的代码来流式传输 USB 相机。按下“开始按钮”后,相机流不会开始。当我先按停止按钮然后按启动按钮时,会显示摄像机流。
我无法理解这种行为。如何使其正常工作?