QT-RTSP相机监控视频流

devtools/2024/9/22 17:28:41/

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.ppmy.cn/devtools/61311.html

相关文章

阿里云服务器 篇三:提交搜索引擎收录

文章目录 系列文章推荐:为网站注册域名判断网站是否已被搜索引擎收录主动提交搜索引擎收录未查询到收录结果时,根据提示进行提交网站提交网站时一般需要登录账号主动提交网站可缩短爬虫发现网站链接时间,但不保证一定能够收录所提交的网站百度提交地址360搜索提交地址搜狗提…

JDK8升级到JDK17,报错Error:java:错误:不支持的发行版本5

1 问题描述&#xff1a; 我原来用到是JDK8,后来重新安装了JDK17后&#xff0c;并更换了JAVA_HOME的配置&#xff0c;在CDM上面查看JAVA版本确认安装无误。 当我打开IDEA运行代码时&#xff0c;就报错java&#xff1a;错误&#xff1a;不支持的发行版本5&#xff0c;至始至终我都…

Mac Electron 应用如何进行签名(signature)和公证(notarization)?

最近很多客户反映&#xff0c;从官网下载的Mac Electron应用打不开&#xff0c;直接报病毒&#xff0c;类似于这种&#xff1a; 这是因为在MacOS 10.14.5之后&#xff0c;如果应用没有在苹果官方平台进行公证notarization(我们可以理解为安装包需要审核&#xff0c;来判断是否存…

【数据流处理和Apache Kafka】使用Kafka进行实时数据流处理

数据流处理和Apache Kafka&#xff1a;使用Kafka进行实时数据流处理 目录 引言Apache Kafka简介 Kafka的架构Kafka的工作原理Kafka的优缺点 Kafka的安装和配置 安装Kafka配置Kafka 使用Kafka进行实时数据流处理 生产者和消费者Kafka Streams示例应用 Kafka的应用案例结论 引言…

Objective-C 自定义渐变色Slider

文章目录 一、前情概要二、具体实现 一、前情概要 系统提供UISlider&#xff0c;但在开发过程中经常需要自定义&#xff0c;本次需求内容是实现一个拥有渐变色的滑动条&#xff0c;且渐变色随着手指touch的位置不同改变区域&#xff0c;类似如下 可以使用CAGradientLayer实现渐…

hexo搭建博客(github node git )(失败版本)

HexoGitHub搭建个人博客教程&#xff08;2023最新版&#xff09; 搭建失败了 是因为git命令一直报错 打算明天把git和node版本全部重新安装后再弄 同时回顾一下github git 和 node的基础知识 Github新手之路&#xff08;全过程&#xff09;&#xff08;站在前辈的肩膀上的总…

推荐一款uniapp拖动验证码插件

插件地址&#xff1a;易盾验证码 - DCloud 插件市场 具体使用方式访问插件地址自行获取

Uniapp中image的@load不触发问题

load 事件不触发的常见情况有以下几种: 图片缓存命中 当图片从浏览器缓存中加载时,load 事件通常不会被触发。这是因为浏览器认为这个图片已经成功加载过了,所以不会再次触发 load 事件。 图片地址未发生变化 如果 image 组件的 src 属性值没有发生变化,即使图片是从网络上加载…