1 Star 0 Fork 8

mehome/qt-ffmpeg-rtsp-video

forked from Luuu/qt-ffmpeg-rtsp-video 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
mainwindow.cpp 2.66 KB
一键复制 编辑 原始数据 按行查看 历史
蝶恋香 提交于 2018-05-29 15:01 . 添加配置读取
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <QtWidgets/QApplication>
#include <QtWidgets/QDesktopWidget>
#include <QtCore/QCommandLineParser>
#include <QtCore/QCommandLineOption>
#include <QtCore/QDir>
#include <QThread>
#include <QPainter>
#include <QInputDialog>
#include <QtMath>
#include <QMouseEvent>
#include <QSettings>
#include <QSettings>
#include <QString>
#include <QDebug>
#include<iostream>
using namespace std;
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
// setWindowFlags(Qt::FramelessWindowHint);
QSettings *configIniRead = new QSettings("config.ini", QSettings::IniFormat);
//将读取到的ini文件保存在QString中,先取值,然后通过toString()函数转换成QString类型
rtspUrl = configIniRead->value("/rtsp/url").toString();
videoPath = configIniRead->value("/video/path").toString();
//读入入完成后删除指针
delete configIniRead;
mPlayer = new VideoPlayer(rtspUrl);
connect(mPlayer,SIGNAL(sig_GetOneFrame(QImage)),this,SLOT(slotGetOneFrame(QImage)));
connect(ui->Open_red,&QAction::triggered,this,&MainWindow::slotOpenRed);
connect(ui->Close_Red,&QAction::triggered,this,&MainWindow::slotCloseRed);
mPlayer->startPlay();
}
MainWindow::~MainWindow()
{
delete ui;
}
void MainWindow::paintEvent(QPaintEvent *event)
{
QPainter painter(this);
//painter.setBrush(QColor(0,0,0,0));
painter.setBrush(Qt::black);
painter.drawRect(0, 0, this->width(), this->height()); //先画成白色
if (mImage.size().width() <= 0) return;
//将图像按比例缩放成和窗口一样大小
QImage img = mImage.scaled(this->size(),Qt::KeepAspectRatioByExpanding);
int x = this->width() - img.width();
int y = this->height() - img.height();
x /= 2;
y /= 2;
painter.drawImage(QPoint(x,y),img); //画出图像
}
void MainWindow::slotGetOneFrame(QImage img)
{
mImage = img;
update(); //调用update将执行 paintEvent函数
}
//小窗口显示
void MainWindow::slotGetRFrame(QImage img)
{
R_mImage = img;
update(); //调用update将执行 paintEvent函数
}
//显示图像红色通道,2017.8.12---lizhen
bool MainWindow::slotOpenRed()
{
open_red=true;
return open_red;
}
//关闭图像红色通道,2017.8.12
bool MainWindow::slotCloseRed()
{
open_red=false;
return open_red;
}
void MainWindow::keyPressEvent(QKeyEvent *event)
{
int key = event->key();
qDebug() << "QKeyEvent:" <<key;
if(key == Qt::Key_A){
vWindow = new videowindow;
vWindow->setAttribute(Qt::WA_DeleteOnClose,true);
vWindow->showFullScreen();
}
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/mehome99/qt-ffmpeg-rtsp-video.git
git@gitee.com:mehome99/qt-ffmpeg-rtsp-video.git
mehome99
qt-ffmpeg-rtsp-video
qt-ffmpeg-rtsp-video
master

搜索帮助