I want to use QNetworkAccessManager get mjpeg stream from specify URL but I am failed.
This is my code :
#include "mainwindow.h"
#include "ui_mainwindow.h"
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
webCam = new QNetworkAccessManager(this);
connect(webCam,SIGNAL(finished(QNetworkReply*)),this,SLOT(replySteamFinish(QNetworkReply*)));
QString cam = "http://192.168.1.1:8080/?action=stream";
QNetworkRequest req;
req.setUrl(cam);
webCam->get(req);
}
MainWindow::~MainWindow()
{
delete ui;
}
void MainWindow::replySteamFinish(QNetworkReply *reply)
{
if(reply->error() == QNetworkReply::NoError){
QByteArray data = reply->readAll();
qDebug() << data;
/*I just test whether receive the mjpeg stream data.*/
}
else{
qDebug() << reply->error();
}
}
I am trying to receive mjpeg stream data,but qDebug() did't work,nothing output. When I put " http://192.168.1.1:8080/?action=stream " in chrome, the web display the mjpeg stream fluent.
How should i fix it? :)
Finally, I use QTcpSocket solve the problem.
#include "mainwindow.h"
#include "ui_mainwindow.h"
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
tcpSocket = new QTcpSocket(this);
tcpSocket->connectToHost("192.168.1.1",8080);
connect(tcpSocket,SIGNAL(readyRead()),this,SLOT(tcpDataReceive()));
}
MainWindow::~MainWindow()
{
delete ui;
}
void MainWindow::tcpDataReceive()
{
QByteArray data = QByteArray::fromHex(tcpSocket->readAll());
qDebug() << data;
}
void MainWindow::on_pushButton_clicked()
{
tcpSocket->write("GET /?action=stream\r\n\r\n");
}
I think the mjpeg stream can not trigger SIGNAL finished,because the mjpeg data allways transfer.So, I choice use SIGNAL readyRead(). :)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.