热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

QCamer的使用

代码如下#-------------------------------------------------##ProjectcreatedbyQtCreator2020-0

代码如下

#-------------------------------------------------
#
# Project created by QtCreator 2020-01-13T10:46:35
#
#-------------------------------------------------QT += core gui
QT += multimedia
QT += multimediawidgetsgreaterThan(QT_MAJOR_VERSION, 4): QT += widgetsTARGET = camera
TEMPLATE = app# The following define makes your compiler emit warnings if you use
# any feature of Qt which as been marked as deprecated (the exact warnings
# depend on your compiler). Please consult the documentation of the
# deprecated API in order to know how to port your code away from it.
DEFINES += QT_DEPRECATED_WARNINGS# You can also make your code fail to compile if you use deprecated APIs.
# In order to do so, uncomment the following line.
# You can also select to disable deprecated APIs only up to a certain version of Qt.
#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0SOURCES += main.cpp\widget.cppHEADERS += widget.hFORMS += widget.ui

#ifndef WIDGET_H
#define WIDGET_H#include
#include
#include
#include namespace Ui {
class Widget;
}class Widget : public QWidget
{Q_OBJECTpublic:explicit Widget(QWidget *parent = 0);~Widget();private slots:void on_openCamera_clicked();void on_closeCamera_clicked();private:Ui::Widget *ui;QCamera* m_camera; //读取摄像头QCameraViewfinder* m_cameraViewFinder; //渲染摄像头};#endif // WIDGET_H

#include "widget.h"
#include "ui_widget.h"Widget::Widget(QWidget *parent) :QWidget(parent),ui(new Ui::Widget)
{ui->setupUi(this);setWindowTitle("Camera");m_camera = new QCamera();m_cameraViewFinder = new QCameraViewfinder();
}Widget::~Widget()
{delete ui;
}void Widget::on_openCamera_clicked()
{ui->cameraShow->addWidget(m_cameraViewFinder); //为QHBoxLayoutm_camera->setViewfinder(m_cameraViewFinder);m_camera->start();
}void Widget::on_closeCamera_clicked()
{m_camera->stop();
}

其它部分省略


推荐阅读
author-avatar
bai小白
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有