QT-RTSP相机监控视频流

QT-RTSP相机监控视频流

  • 一、演示效果
  • 二、关键程序
  • 三、下载链接

一、演示效果

在这里插入图片描述

二、关键程序

#include "mainwindow.h"#include <QDebug>MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), m_settings("outSmart", "LiveWatcher") {ip_address_edit = new QLineEdit;login_edit = new QLineEdit;password_edit = new QLineEdit;password_edit->setEchoMode(QLineEdit::Password);label0 = new QLabel;label0->setText("IP address:");label1 = new QLabel;label1->setText("Login:");label2 = new QLabel;label2->setText("Password:");button1 = new QPushButton;button1->setText("Connect");connect(button1, SIGNAL(clicked()), SLOT(slotConnectDisconnect()) );videoWidget = new VideoWidget(this);videoWidget->setMinimumSize(704, 576);player0 = new QMediaPlayer;player0->setVideoOutput(videoWidget);layout1 = new QVBoxLayout;layout1->addWidget(label0);layout1->addWidget(ip_address_edit);layout1->addWidget(label1);layout1->addWidget(login_edit);layout1->addWidget(label2);layout1->addWidget(password_edit);spacer0 = new QSpacerItem(30, 40, QSizePolicy::Minimum, QSizePolicy::Maximum);layout1->addSpacerItem(spacer0);layout1->addWidget(button1);layout1->setContentsMargins(10, 10, 10, 10);layout2 = new QVBoxLayout;layout2->addWidget(videoWidget);layout0 = new QHBoxLayout;layout0->addLayout(layout2);layout0->addLayout(layout1);layout0->setAlignment(layout1, Qt::AlignTop) ;QWidget * window = new QWidget();window->setLayout(layout0);setCentralWidget(window);QRegExpValidator *ipValidator = new QRegExpValidator(ipRegex, this);ip_address_edit->setValidator(ipValidator);readSettings();QAction* pactShowHide = new QAction("&Show/Hide Application Window", this);connect(pactShowHide, SIGNAL(triggered()),this,         SLOT(slotShowHide()));QAction* pactQuit = new QAction("&Quit", this);connect(pactQuit, SIGNAL(triggered()), qApp, SLOT(quit()));m_ptrayIconMenu = new QMenu(this);m_ptrayIconMenu->addAction(pactShowHide);m_ptrayIconMenu->addAction(pactQuit);m_ptrayIcon = new QSystemTrayIcon(this);m_ptrayIcon->setContextMenu(m_ptrayIconMenu);m_ptrayIcon->setToolTip("LiveWatcher");m_ptrayIcon->setIcon(QPixmap(":/images/logo.png"));m_ptrayIcon->show();createMenus();}MainWindow::~MainWindow()
{writeSettings();
}void MainWindow::slotConnectDisconnect()
{if (!is_connected) {QString login = login_edit->text() ;QString password = password_edit->text() ;QString ip_address = ip_address_edit->text() ;if (!ipRegex1.match(ip_address).hasMatch() ) {QMessageBox::critical(this, "Error", "Wrong format for IP address");return;}url0 = QUrl("rtsp://" + ip_address + ":554/ISAPI/Streaming/Channels/102");url0.setUserName(login);url0.setPassword(password);requestRtsp0 = QNetworkRequest(url0);player0->setMedia(requestRtsp0);player0->play();is_connected = true;button1->setText("Disconnect");}else {player0->stop();button1->setText("Connect");is_connected = false;}}void MainWindow::keyPressEvent(QKeyEvent *event)
{if (event->key() == Qt::Key_F11) {if (videoWidget != nullptr) {videoWidget->setFullScreen(true);}}else if (event->key() == Qt::Key_Escape) {qApp->quit();}}void MainWindow::writeSettings() {m_settings.beginGroup("/Settings");m_settings.setValue("/ip_address", ip_address_edit->text() ) ;m_settings.setValue("/login", login_edit->text() );m_settings.setValue("/password", password_edit->text() );m_settings.endGroup();}void MainWindow::readSettings() {m_settings.beginGroup("/Settings");ip_address_edit->setText(m_settings.value("/ip_address", "").toString() );login_edit->setText(m_settings.value("/login", "admin").toString() );password_edit->setText(m_settings.value("/password", "Freedom!00##").toString() );m_settings.endGroup();}void MainWindow::slotShowHide()
{setVisible(!isVisible());
}void MainWindow::closeEvent(QCloseEvent * event)
{setVisible(false);event->ignore();
}void MainWindow::showAbout() {QMessageBox::about(this, "About", "aleks.twin@gmail.com");}void MainWindow::createMenus()
{QAction *quit = new QAction("&Quit", this);QMenu *file;file = menuBar()->addMenu(tr("&File"));file->addAction(quit);connect(quit, &QAction::triggered, qApp, QApplication::quit);QMenu *settingsMenu;settingsMenu = menuBar()->addMenu(tr("&Settings"));QAction * colorSettingsAct = new QAction(tr("&Color settings"), this);colorSettingsAct->setStatusTip(tr("Show color settings"));connect(colorSettingsAct, &QAction::triggered, this, &MainWindow::showColorDialog);settingsMenu->addAction(colorSettingsAct);QMenu *helpMenu;helpMenu = menuBar()->addMenu(tr("&Help"));QAction * hotKeysAct = new QAction(tr("&Hot keys"), this);connect(hotKeysAct, &QAction::triggered, this, &MainWindow::showHotKeys);helpMenu->addAction(hotKeysAct);helpMenu->addSeparator();QAction * aboutAct = new QAction(tr("&About"), this);aboutAct->setStatusTip(tr("Create a new file"));connect(aboutAct, &QAction::triggered, this, &MainWindow::showAbout);helpMenu->addAction(aboutAct);}void MainWindow::showColorDialog() {if (!m_colorDialog) {QSlider *brightnessSlider = new QSlider(Qt::Horizontal);brightnessSlider->setRange(-100, 100);brightnessSlider->setValue(videoWidget->brightness());connect(brightnessSlider, &QSlider::sliderMoved, videoWidget, &QVideoWidget::setBrightness);connect(videoWidget, &QVideoWidget::brightnessChanged, brightnessSlider, &QSlider::setValue);QSlider *contrastSlider = new QSlider(Qt::Horizontal);contrastSlider->setRange(-100, 100);contrastSlider->setValue(videoWidget->contrast());connect(contrastSlider, &QSlider::sliderMoved, videoWidget, &QVideoWidget::setContrast);connect(videoWidget, &QVideoWidget::contrastChanged, contrastSlider, &QSlider::setValue);QSlider *hueSlider = new QSlider(Qt::Horizontal);hueSlider->setRange(-100, 100);hueSlider->setValue(videoWidget->hue());connect(hueSlider, &QSlider::sliderMoved, videoWidget, &QVideoWidget::setHue);connect(videoWidget, &QVideoWidget::hueChanged, hueSlider, &QSlider::setValue);QSlider *saturationSlider = new QSlider(Qt::Horizontal);saturationSlider->setRange(-100, 100);saturationSlider->setValue(videoWidget->saturation());connect(saturationSlider, &QSlider::sliderMoved, videoWidget, &QVideoWidget::setSaturation);connect(videoWidget, &QVideoWidget::saturationChanged, saturationSlider, &QSlider::setValue);QFormLayout *layout = new QFormLayout;layout->addRow(tr("Brightness"), brightnessSlider);layout->addRow(tr("Contrast"), contrastSlider);layout->addRow(tr("Hue"), hueSlider);layout->addRow(tr("Saturation"), saturationSlider);QPushButton *button = new QPushButton(tr("Close"));layout->addRow(button);m_colorDialog = new QDialog(this, Qt::WindowSystemMenuHint | Qt::WindowTitleHint);m_colorDialog->setWindowTitle(tr("Color Options"));m_colorDialog->setLayout(layout);connect(button, &QPushButton::clicked, m_colorDialog, &QDialog::close);}m_colorDialog->show();
}void MainWindow::showHotKeys() {QLabel * q_label = new QLabel();q_label->setStyleSheet(styleSheet() );q_label->setText("F11 - full screeen\nEcsape - exit full screen\n");q_label->setContentsMargins(10,10,10,10);q_label->setWindowTitle("Hot keys");q_label->setFixedSize(240, 60);q_label->show();
}

#include "videowidget.h"#include <QKeyEvent>
#include <QMouseEvent>VideoWidget::VideoWidget(QWidget *parent): QVideoWidget(parent)
{setSizePolicy(QSizePolicy::Ignored, QSizePolicy::Ignored);QPalette p = palette();p.setColor(QPalette::Window, Qt::black);setPalette(p);setAttribute(Qt::WA_OpaquePaintEvent);
}void VideoWidget::keyPressEvent(QKeyEvent *event)
{if (event->key() == Qt::Key_Escape && isFullScreen()) {setFullScreen(false);event->accept();} else {QVideoWidget::keyPressEvent(event);}
}void VideoWidget::mouseDoubleClickEvent(QMouseEvent *event)
{setFullScreen(!isFullScreen());event->accept();
}void VideoWidget::mousePressEvent(QMouseEvent *event)
{QVideoWidget::mousePressEvent(event);
}

三、下载链接

https://download.csdn.net/download/u013083044/89550321

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/872864.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

清华大学学报哲学社会科学版

《清华大学学报》&#xff08;哲学社会科学版&#xff09;投稿须知 一、本刊简介 《清华大学学报》&#xff08;哲学社会科学版&#xff09;由清华大学主办&#xff0c;是首批国家社会科学基金资助期刊、全国中文核心期刊、中国人文社会科学核心期刊、中文社会科学引文索引&…

Gmsh教程

13、在没有底层CAD模型的情况下重新擦除STL文件 import gmsh # 导入Gmsh库&#xff0c;用于几何建模和网格划分 import math # 导入数学库&#xff0c;用于计算 import os # 导入操作系统库&#xff0c;用于处理文件路径 import sys # 导入系统库&#xff0c;用于…

CentOS 7 安装MySQL 5.7.30

CentOS 7 安装MySQL卸载&#xff08;离线安装&#xff09; 安装配置MySQL之前先查询是否存在&#xff0c;如存在先卸载再安装 rpm -qa|grep -i mysql rpm -qa|grep -i mariadb rpm -e --nodeps mariadb-libs-5.5.68-1.el7.x86_64如下命令找到直接 rm -rf 删除&#xff08;删除…

07. Hibernate 会话工厂(SessionFactory)

1. 前言 Hibernate 的核心价值观是&#xff1a;开发者们&#xff01;做你们应该做的。脏的、累的、没技术含义的由本尊来做。 本节课和大家一起好好的聊聊 Hibernate 的核心组件之一&#xff1a;会话工厂&#xff08;SessionFactory&#xff09;。 通过本节课&#xff0c;你…

Redis数据结构--跳跃表 Skip List

跳跃表&#xff08;Skip List&#xff09;是一种高效的随机化数据结构&#xff0c;通过引入多层索引来实现快速的查找、插入和删除操作。它在Redis中被用来实现有序集合&#xff08;Sorted Set&#xff09;&#xff0c;在处理大量数据时表现出了优越的性能和灵活性。本文将详细…

MySQL增量备份

增备1 做增量备份前&#xff0c;是需要进行一次完成备份的 1、做数据修改 创建一个add1.t1 t1 包含&#xff1a;id,name 加2条数据 id | name | ---------- | 1 | add1 | | 2 | add2 | ----------操作如下&#xff1a; MySQL root(none):(none)> show databases; -…

Linux openEuler_24.03部署MySQL_8.4.0 LTS安装实测验证安装以及测试连接全过程实操手册

Linux openEuler_24.03部署MySQL_8.4.0 LTS安装实测验证安装以及测试连接全过程实操手册 前言: 什么是 MySQL? MySQL 是一个关系型数据库管理系统,由瑞典 MySQL AB 公司开发,目前属于Oracle 公司。MySQL 是一种关系型数据库管理系统,关系型数据库将数据保存在不同的表中,…

深入探讨SQL Server端口设置:理论与实践

引言 在现代企业级应用中&#xff0c;SQL Server作为微软的旗舰数据库产品&#xff0c;广泛应用于各种关键业务系统中。设置SQL Server的端口是数据库管理中的一个重要环节&#xff0c;它不仅影响到数据库的安全性&#xff0c;还直接关系到网络通信的效率和稳定性。本文将从计…

C++ 入门基础:开启编程之旅

文章目录 引言一、C的第⼀个程序二、命名空间1、namespace2、namespace的定义 三、C输入 与 输出四、缺省参数五、函数重载六、引用1、引用的概念和定义2、引用的特性3、指针和引用的关系七、inline八、nullptr 引言 C 是一种高效、灵活且功能强大的编程语言&#xff0c;广泛应…

C1W4.Assignment.Naive Machine Translation and LSH

理论课&#xff1a;C1W4.Machine Translation and Document Search 文章目录 1. The word embeddings data for English and French words1.1The dataThe subset of dataLoad two dictionaries 1.2 Generate embedding and transform matricesExercise 1: Translating English…

数学建模-Topsis(优劣解距离法)

介绍 TOPSIS法&#xff08;Technique for Order Preference by Similarity to Ideal Solution&#xff09; 可翻译为逼近理想解排序法&#xff0c;国内常简称为优劣解距离法 TOPSIS 法是一种常用的综合评价方法&#xff0c;其能充分利用原始数据的信息&#xff0c; 其结果能精…

张量分解(5)——Tucker分解

&#x1f345; 写在前面 &#x1f468;‍&#x1f393; 博主介绍&#xff1a;大家好&#xff0c;这里是hyk写算法了吗&#xff0c;一枚致力于学习算法和人工智能领域的小菜鸟。 &#x1f50e;个人主页&#xff1a;主页链接&#xff08;欢迎各位大佬光临指导&#xff09; ⭐️近…

如何防范场外个股期权的交易风险?

场外个股期权交易&#xff0c;作为金融衍生品市场的重要组成部分&#xff0c;为投资者提供了更为灵活和多样化的投资策略。然而&#xff0c;其高杠杆、高风险特性也使得投资者在追求高收益的同时&#xff0c;面临着较大的交易风险。为了有效防范这些风险&#xff0c;投资者需要…

基于STM32设计的智能门锁(微信小程序+手机APP等多种方式开锁)(188)

基于STM32设计的智能门锁(微信小程序+手机APP等多种方式开锁)(188) 文章目录 一、前言1.1 项目介绍【1】项目功能介绍【2】项目硬件模块组成1.2 设计思路【1】整体设计思路【2】整体构架【3】ESP8266模块配置【4】上位机开发思路【5】供电方式1.3 项目开发背景【1】选题的意义【…

Kafka Producer发送消息流程之Sender发送线程和在途请求缓存区

文章目录 1. Sender发送数据1. 发送数据的详细过程&#xff1a;2. 关键参数配置 2. 在途请求缓存区 1. Sender发送数据 Sender线程负责将已经在RecordAccumulator中准备好的消息批次发送到Kafka集群。虽然消息在RecordAccumulator中是按照分区组织的&#xff0c;但Sender线程在…

【VScode】安装【ESP-IDF】插件及相关工具链

一、ESP-IDF简介 二、VScode安装ESP-IDF插件 三、安装ESP-IDF、ESP-IDF-Tools以及相关工具链 四、测试例程&编译烧录 一、ESP-IDF简介 二、VScode安装ESP-IDF插件 【VScode】安装配置、插件及远程SSH连接 【VSCode】自定义配置 打开VScode&#xff0c;在插件管理搜索esp…

react + pro-components + ts完成单文件上传和批量上传

上传部分使用的是antd中的Upload组件,具体如下: GradingFilingReportUpload方法是后端已经做好文件流,前端只需要调用接口即可 单文件上传 <Uploadkey{upload_${record.id}}showUploadList{false}accept".xlsx"maxCount{1}customRequest{({ file }) > {const …

linux list

list_add list_add_tail

网络安全(含面试题版)

一、网络概念 网络&#xff1a;一组相互连接的计算机&#xff0c;多台计算机组成&#xff0c;使用物理线路进行连接 作用&#xff1a; 数据交换 资源共享 二、网络分类 计算机网络覆盖的地理区域决定了它的类型。一般分为局域网(LAN)、城域网(MAN)、广域网(WAN)。 三、www万维网…

06MFC之对话框--重绘元文件

文章目录 实现示例展示需要绘制的窗口/位置控件位置更新下一次示例粗细滑动部分更新重绘元文件(窗口变化内容消失)方法一:使用元文件方法二:兼容设备方法三:使用自定义类存储绘图数据除画笔外功能处理画笔功能处理保存前面画的线及色彩实现示例展示 需要绘制的窗口/位置 …