1.widget.cpp
#include "widget.h"
#include <QDebug>
Widget::Widget(QWidget *parent)
: QWidget(parent)
{
this->resize(640, 480);
// 请根据各自的摄像头节点填写
m_qcamera = new QCamera("/dev/video0", this);
if (!m_qcamera) {
qDebug() << "摄像头初始化失败!";
}
QCameraViewfinderSettings settings;
// 设置分辨率
settings.setResolution(640, 480);
m_qcamera->setViewfinderSettings(settings);
m_videoWidget = new QVideoWidget(this);
m_videoWidget->resize(this->size());
// 设置视频输出
m_qcamera->setViewfinder(m_videoWidget);
m_qcamera->start();
// 注m_videoWidget有可能刷新延时,可能是Qt底层刷新问题
// 这里用QVideoWidget只是用于测试,请用update()延时更新
m_videoWidget->show();
}
Widget::~Widget()
{
}
2.widget.h
#ifndef WIDGET_H
#define WIDGET_H
#include <QWidget>
#include <QCamera>
#include <QVideoWidget>
class Widget : public QWidget
{
Q_OBJECT
public:
Widget(QWidget *parent = nullptr);
~Widget();
// 声明对象
QCamera *m_qcamera;
QVideoWidget *m_videoWidget;
};
#endif // WIDGET_H
3.效果
标签:Widget,USB,DLRK3568,QVideoWidget,qcamera,ATK,QWidget,videoWidget,include From: https://blog.csdn.net/weixin_43756274/article/details/144226113