I am a newbee when it comes to coding in C++.
I am currently using qt to make a simple GUI, where I want to send a command to a device via TCP/IP.
When i connect my computer to the device and via the terminal send the command:
echo '3b00010000001b010001000000120000013000002713000300030101' | xxd -r -p | nc 192.168.1.101 30013
The device does correspondently.
I need to be able to send this command in qt as a function. Can anyone help me? This is what i have so far (does not work)
Header:
#ifndef SOCKET_H
#define SOCKET_H
#include <QObject>
#include <QTcpSocket>
#include <QtDebug>
#include <string>
using namespace std;
class Socket : public QObject
{
Q_OBJECT
public:
explicit Socket(QObject *parent = nullptr);
void Connect(const QString &host, const string &cmd);
private:
QTcpSocket *socket;
};
#endif // SOCKET_H
Cpp:
#include "socket.h"
Socket::Socket(QObject *parent) : QObject(parent)
{
}
void Socket::Connect(const QString &host, const string &cmd)
{
//connect
socket = new QTcpSocket(this);
socket->connectToHost(host,30013);
if(socket->waitForConnected(1500))
{
qDebug() << "Connected";
//send
socket->write(cmd.c_str(), cmd.size());
socket->waitForBytesWritten(1000);
//close
socket->close();
}
else
qDebug() << "Not Connected";
}
Then I want to send the command by:
Socket.Test
Test.Connect("192.168.1.101","3b00010000001b010001000000120000013000002713000300030101")
Any help would be much appreciated. Thanks.
As your command is a fixed string you can simply enter the characters directly:
const char data[] = "\x3b\x00\x01\x00\x00\x00\x1b\x01\x00\x01\x00\x00\x00\x12\x00\x00\x01\x30\x00\x00\x27\x13\x00\x03\x00\x03\x01\x01";
Test.Connect("192.168.1.101",string(data, sizeof(data)-1));
Note that as your data has embedded null characters you can't simply pass the string literal to std::string as it would truncate the string before the first null character.
Related
I have a simple program that should retrieve the HTML from a website URL.
main.cpp
#include "Downloader.h"
#include <QCoreApplication>
int main(int argc, char *argv[])
{
QCoreApplication a(argc, argv);
auto dl = new Downloader(&a);
QString url = "https://www.dognow.at/ergebnisse/?page=1";
dl->fetch(url);
return a.exec();
}
Downloader.h
#ifndef DOWNLOADER_H
#define DOWNLOADER_H
#include <QNetworkReply>
#include <QObject>
class Downloader : public QObject
{
Q_OBJECT
public:
explicit Downloader(QObject* parent = nullptr);
void fetch(QString &url);
private:
QNetworkAccessManager* m_manager;
private slots:
void replyFinished(QNetworkReply* rep);
};
#endif // DOWNLOADER_H
Downloader.cpp
#include "Downloader.h"
#include <QDebug>
Downloader::Downloader(QObject* parent): QObject(parent),
m_manager(new QNetworkAccessManager(parent))
{}
void Downloader::fetch(QString& url)
{
qDebug() << "fetch " << url;
connect(m_manager, &QNetworkAccessManager::finished, this, &Downloader::replyFinished);
m_manager->get(QNetworkRequest(QUrl(url)));
}
void Downloader::replyFinished(QNetworkReply* rep)
{
QByteArray data=rep->readAll();
QString str(data);
qDebug() << "data len: " << str.length();
rep->close();
}
When I run the program on my local PC it works fine. When I run it on another machine the reply data is empty. On both systems I use Linux (x86_64) and Qt 5.15.0.
I hope someone can give me a hint where I should have a look at.
UPDATE: 2022-04-04 - 16:22:
when I run a simple curl command on the failing machine it works fine.
Ok, I found the problem.
On the failing machin I have an older ubuntu (16.04 LTS) running with an incompatible openssl version.
I found it out because I copied my own Qt libs build (debug) to the other machine and I got SSL error (incompatbile version).
I installed a newer openssl version and know it works.
For some application I need to scan WiFi searching for available network (SSID). On Ubuntu 18.04 LTS I don't have any issue with the fallowing code. It return all available SSID as expected but when running on Raspbian stretch (Rasberry PI 3 b) the fallowing code is returning the interface wlan0 and eth0 and not the SSID. Does someone have any clue why? or can tell me what I miss? On the other hand, is it better not to use Qt network lib and use a QProcess and parse what sudo iwlist wlan0 scan is returning?
.cpp
void wificonfig::findavailableWifinetwork( void )
{
QNetworkConfigurationManager ncm;
netconflist = ncm.allConfigurations(QNetworkConfiguration::Discovered); //
int i =0;
awifilist.clear();
for(auto &x : netconflist){
if ((x.bearerType() == QNetworkConfiguration::BearerWLAN) ){
if(x.name() == "")
awifilist << "Unknown(Other Network)";
else{
ui->wificonnection_tw->setItem(i, 0, new QTableWidgetItem(x.name()));
i++;
}
//qDebug() << x.type();
}
}
ui->wificonnection_tw->setRowCount(i);
}
.h
#ifndef WIFICONFIG_H
#define WIFICONFIG_H
#include <QList>
#include <QTimer>
#include <QDialog>
#include <QNetworkConfiguration>
#include <QNetworkConfigurationManager>
#include <QNetworkSession>
namespace Ui {
class wificonfig;
}
class wificonfig : public QDialog
{
Q_OBJECT
public:
explicit wificonfig(QWidget *parent = 0);
~wificonfig();
int connection_count;
QNetworkConfiguration netconf;
QStringList awifilist;
QList<QNetworkConfiguration>netconflist;
public slots:
void findavailableWifinetwork( void );
private slots:
void on_wifi_scan_butt_clicked();
private:
Ui::wificonfig *ui;
QTime *scan_timeout_timer;
QNetworkSession *session;
};
#endif // WIFICONFIG_H
What I'm trying to achieve (And struggling with) is basically passing commands to CMD through my QT Mainwindow application.
I would like to have my code, first run CMD (preferably hidden). I used here QProcess like this:
(in my Mainwindow.cpp file)
QString exePath = "C:/Windows/System32/cmd.exe";
QProcess pro;
pro.startDetached(exePath);
pro.waitForStarted();
this question helped me a lot
However, what this answer/question lacks is actual help on "appending" commands to CMD (not sure if this is a correct term, please correct me if I'm wrong!)
I have tried the following with this piece of code
(also in my Mainwindow.cpp file)
string exepathstring = "C:/Windows/System32/cmd.exe"; //because fstream doesnt accept argument of type QString
QProcess pro;
pro.startDetached(exePath); //do I have to use "detached" here?
pro.waitForFinished(); //not sure if i should use "for
//finished" or "for started" or something else
string connecttoserver = ui->lineEdit_command->text().toStdString(); //this is where people input a cmd command
//need to convert it to to be able to append it
fstream myoutfile(exepathstring, ios::in | ios::out | ios::app);
myoutfile <<""<< connecttoserver << endl;
Hoping that I can use a normal "append to file" code but it does nothing, I don't even get an error :(
could someone tell me where i'm going wrong?
and how can I go about achieving what I want?
which is
starting cmd (preferably in hidden) upon launch of my "mainwindow app"
take user input and let my app pass it to cmd upon my button click.
Here's my entire mainwindow.cpp source file
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <QProcess>
#include <QString>
#include <fstream>
#include <iostream>
using namespace std;
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{ui->setupUi(this);}
MainWindow::~MainWindow()
{delete ui;}
void MainWindow::on_pushButton_clicked()
{
QString exePath = "C:/Windows/System32/cmd.exe";
string exepathstring = "C:/Windows/System32/cmd.exe"; //because fstream doesnt accept argument of type QString
QProcess pro;
pro.startDetached(exePath);
pro.waitForFinished(); //not sure if i should use "for finished" or "for started" or something else
string connecttoserver = ui->lineEdit_command->text().toStdString(); /*this is where people input a cmd command
need to convert it to to be able to append it*/
fstream myoutfile(exepathstring, ios::in | ios::out | ios::app);
myoutfile <<""<< connecttoserver << endl;
}
Any input would really help me a lot ^.^ also I'm really sorry if I had used wrong terminology
If you looked at this post, one apparent problem is that you are using the static method startDetached() with the blocking function waitForFinished() ... QProcess::waitForStarted()/waitForFinished() won't catch signals from detached QProcess;
Thus you could use:
QProcess pro;
pro.start(exePath);
pro.waitForStarted(); // the correct is `waitForStarted()`
What your trying to do with fstream is not clear - to me - while in your description, you want user to send a command to your process:
then this could, for instance, be :
QByteArray user_cmd = QVariant(ui->lineEdit_command->text()).toByteArray();
pro.write(user_cmd);
pro.write("\n\r"); // press Enter to execute the command
Thus your code could be:
.h
#include <QProcess>
namespace Ui {
class MainWindow;
}
class MainWindow : public QMainWindow
{
Q_OBJECT
public:
explicit MainWindow(QWidget *parent = 0);
~MainWindow();
private slots:
void readResult();
void on_pushButton_clicked();
private:
Ui::MainWindow *ui;
QProcess* pro;
};
.cpp
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <QString>
#include <QDebug>
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
connect(ui->pushButton, &QPushButton::clicked, this, &MainWindow::on_pushButton_clicked);
QString exePath = "C:/Windows/System32";
pro = new QProcess(parent);
pro->setWorkingDirectory(exePath);
pro->setReadChannel(QProcess::StandardOutput);
connect(pro,&QProcess::readyReadStandardOutput, this, &MainWindow::readResult);
pro->start("cmd.exe");
if (!pro->waitForStarted())
{
qDebug() << "The process didnt start" << pro->error();
}
}
void MainWindow::on_pushButton_clicked()
{
if (ui->lineEdit_command->text().isEmpty())
return;
QByteArray cmd = QVariant(ui->lineEdit_command->text()).toByteArray();
pro->write(cmd);
pro->write("\n\r");
ui->lineEdit_command->clear();
}
void MainWindow::readResult()
{
while(pro->bytesAvailable()){
QString dirout = pro->readLine();
qDebug() << dirout;
}
}
MainWindow::~MainWindow()
{
delete ui;
}
I've been looking around on the web on how to create an authentication page when my Qt desktop app opens. I already built the app; that is pretty small and only composed of a MainWindow called from main.cpp.
Now I'd like to add an authentication page when the user opens the app. I created a Google API (following the instruction from this link: http://blog.qt.io/blog/2017/01/25/connecting-qt-application-google-services-using-oauth-2-0/); but it is really incomplete. And looking on the web, I wasn't able to find a single link that gives a working example where:
- The user runs the app and gets asked for his username and password;
- And if it doesn't exist yet, he can create one.
All I've found is incomplete piece of code like the link I shared above; or tutorial that shows how to create a login page with hard-coded passwords and usernames (this is not what I want, I want people to be able to add themselves dynamically based of the Google API).
So please, if someone has a little piece of code where the user gets asked for their username and password, with the code managing the request to the API, that would be great!
EDIT: Adding my code
I'm adding the code of my class GoogleGateway (inspired from what I found here: How to set redirect_uri using QOAuth2AuthorizationCodeFlow and QOAuthHttpServerReplyHandler)
GoogleGateway.h:
#ifndef GOOGLEGATEWAY_H
#define GOOGLEGATEWAY_H
#include <QObject>
class GoogleGateway : public QObject
{
Q_OBJECT
public:
GoogleGateway();
};
#endif // GOOGLEGATEWAY_H
GoogleGateway.cpp:
#include "googlegateway.h"
#include <QApplication>
#include <QObject>
#include <QJsonDocument>
#include <QJsonObject>
#include <QJsonArray>
#include <QString>
#include <QFile>
#include <QUrl>
#include <QOAuth2AuthorizationCodeFlow>
#include <QOAuthHttpServerReplyHandler>
#include <QDesktopServices>
GoogleGateway::GoogleGateway() :
QObject(){
auto google = new QOAuth2AuthorizationCodeFlow;
google->setScope("email");
this->connect(google, &QOAuth2AuthorizationCodeFlow::authorizeWithBrowser, &QDesktopServices::openUrl);
QString val;
QFile file;
file.setFileName("/.../auth.json");
file.open(QIODevice::ReadOnly | QIODevice::Text);
val = file.readAll();
file.close();
QJsonDocument document = QJsonDocument::fromJson(val.toUtf8());
QJsonObject object = document.object();
const auto settingsObject = object["web"].toObject();
const QUrl authUri(settingsObject["auth_uri"].toString());
const auto clientId = settingsObject["client_id"].toString();
const QUrl tokenUri(settingsObject["token_uri"].toString());
const auto clientSecret(settingsObject["client_secret"].toString());
const auto redirectUris = settingsObject["redirect_uris"].toArray();
const QUrl redirectUri(redirectUris[0].toString());
const auto port = static_cast<quint16>(redirectUri.port());
google->setAuthorizationUrl(authUri);
google->setClientIdentifier(clientId);
google->setAccessTokenUrl(tokenUri);
google->setClientIdentifierSharedKey(clientSecret);
auto replyHandler = new QOAuthHttpServerReplyHandler(port, this);
google->setReplyHandler(replyHandler);
google->grant();
}
Now, what do I need to do in my MainWindow.cpp to prompt a login page that will use the class GoogleGateway? Does the class GoogleGateway look good as it is? Or do I need to modify something?
Also, I created an instance of the class GoogleGateway in my MainWindow constructor. And When I run the code, it opens a web tab in my Chrome but throws the Error 400 saying "Error: redirect_uri_mismatch". What does that mean?
Thanks for your help.
So, the article from Qt blog is almost complete. You just need to connect granted signal and make needed requests after that.
Note about /cb path in redirect_uri in Qt blog is not valid anymore(article came about a year ago).
NOTE: The path “/cb” is mandatory in the current
QOAuthHttpServerReplyHandler implementation.
So if you see access error from google after running your code, just copy-paste redirect_uri from there into GoogleConsole Authorized redirect URIs of your configured client. http://localhost:8080/ <- don't forget slash at the end
P.S.: Don't forget to dowload json file with credentials from console again.
Also if you want to call any Google APIs after authorization, you need to enable them in GoogleConsole for your project. To test the code just enable Google+ API
That's it. Here is the complete and working code. (Tested on Linux and Qt 5.10, Don't have Windows at the moment, can't test it there)
googlegateway.h
#ifndef GOOGLEGATEWAY_H
#define GOOGLEGATEWAY_H
#include <QObject>
#include <QOAuth2AuthorizationCodeFlow>
#include <QNetworkReply>
class GoogleGateway : public QObject
{
Q_OBJECT
public:
explicit GoogleGateway(QObject *parent = nullptr);
private:
QOAuth2AuthorizationCodeFlow * google;
};
#endif // GOOGLEGATEWAY_H
googlegateway.cpp
#include "googlegateway.h"
#include <QObject>
#include <QJsonDocument>
#include <QJsonObject>
#include <QJsonArray>
#include <QString>
#include <QFile>
#include <QDir>
#include <QUrl>
#include <QOAuthHttpServerReplyHandler>
#include <QDesktopServices>
GoogleGateway::GoogleGateway(QObject *parent) : QObject(parent)
{
this->google = new QOAuth2AuthorizationCodeFlow(this);
this->google->setScope("email");
connect(this->google, &QOAuth2AuthorizationCodeFlow::authorizeWithBrowser, &QDesktopServices::openUrl);
QByteArray val;
QFile file;
file.setFileName(QDir::toNativeSeparators("/full/path/client_secret_XXXXXXX.apps.googleusercontent.com.json"));
if(file.open(QIODevice::ReadOnly | QIODevice::Text))
{
val = file.readAll();
file.close();
}
QJsonDocument document = QJsonDocument::fromJson(val);
QJsonObject object = document.object();
const auto settingsObject = object["web"].toObject();
const QUrl authUri(settingsObject["auth_uri"].toString());
const auto clientId = settingsObject["client_id"].toString();
const QUrl tokenUri(settingsObject["token_uri"].toString());
const auto clientSecret(settingsObject["client_secret"].toString());
const auto redirectUris = settingsObject["redirect_uris"].toArray();
const QUrl redirectUri(redirectUris[0].toString());
const auto port = static_cast<quint16>(redirectUri.port());
this->google->setAuthorizationUrl(authUri);
this->google->setClientIdentifier(clientId);
this->google->setAccessTokenUrl(tokenUri);
this->google->setClientIdentifierSharedKey(clientSecret);
auto replyHandler = new QOAuthHttpServerReplyHandler(port, this);
this->google->setReplyHandler(replyHandler);
this->google->grant();
connect(this->google, &QOAuth2AuthorizationCodeFlow::granted, [=](){
qDebug() << __FUNCTION__ << __LINE__ << "Access Granted!";
auto reply = this->google->get(QUrl("https://www.googleapis.com/plus/v1/people/me"));
connect(reply, &QNetworkReply::finished, [reply](){
qDebug() << "REQUEST FINISHED. Error? " << (reply->error() != QNetworkReply::NoError);
qDebug() << reply->readAll();
});
});
}
Please remember to set Redirect URI in google console to http://127.0.0.1:port_no/ instead of http://localhost:port_no/ for all localhost.
Remember to put the trailing '/' in the Redirect URI.
Rest of the code
this->google = new QOAuth2AuthorizationCodeFlow(this);
this->google->setScope("email");
connect(this->google, &QOAuth2AuthorizationCodeFlow::authorizeWithBrowser, &QDesktopServices::openUrl);
this->google->setAuthorizationUrl(QUrl("https://accounts.google.com/o/oauth2/auth"));
this->google->setClientIdentifier(MY_CLIENT_ID);
this->google->setAccessTokenUrl(QUrl("https://oauth2.googleapis.com/token"));
this->google->setClientIdentifierSharedKey(MYTOKEN);
// In my case, I have hardcoded 8080 to test
auto replyHandler = new QOAuthHttpServerReplyHandler(8080, this);
this->google->setReplyHandler(replyHandler);
this->google->grant();
qDebug() << "Access";
connect(this->google, &QOAuth2AuthorizationCodeFlow::granted, [=](){
qDebug() << __FUNCTION__ << __LINE__ << "Access Granted!";
auto reply = this->google->get(QUrl("https://www.googleapis.com/plus/v1/people/me"));
connect(reply, &QNetworkReply::finished, [reply](){
qDebug() << "REQUEST FINISHED. Error? " << (reply->error() != QNetworkReply::NoError);
qDebug() << reply->readAll();
});
});
I have set up a server and video streaming so that I can connect to the stream with ffplay using the following command line:
ffplay rtmp://<IP>/path
Is it possible to use QMediaPlayer QMediaContent or something to connect to this stream?
Or maybe any other kind of stream I can create with ffserver.
using the same path as with ffplay results in "Unsupported url scheme!"
With further experiments i have tried ffserver http server streaming, but that ended with Qt crashing in MFStreamer::doRead()
Apparently it should have called BeginRead for MFStreamer but it didn't.
How do i play video streams with QMediaPlayer?
Edit: here's my code
videotest.cpp
#include "videotest.h"
#include <QVBoxLayout>
#include <QVideoWidget>
#include <qmediaplayer.h>
#include <QMediaContent>
#include <QNetworkAccessManager>
#include <QNetworkReply>
struct VideoTest::Private
{
QMediaPlayer * mediaPlayer;
QNetworkAccessManager * networkAccessManager;
QNetworkReply * reply;
};
VideoTest::VideoTest(QWidget *parent)
: QMainWindow(parent)
{
d = new Private;
d->mediaPlayer = new QMediaPlayer(this, QMediaPlayer::StreamPlayback);
d->networkAccessManager = new QNetworkAccessManager(this);
ui.setupUi(this);
QVideoWidget * videoWidget = new QVideoWidget(ui.centralWidget);
videoWidget->show();
QPalette palette = videoWidget->palette();
palette.setColor(QPalette::Background, QColor(0, 0, 0));
videoWidget->setPalette(palette);
ui.videoLayout->addWidget(videoWidget);
d->mediaPlayer->setVideoOutput(videoWidget);
connect(ui.playButton, SIGNAL(clicked()), d->mediaPlayer, SLOT(play()));
connect(ui.pauseButton, SIGNAL(clicked()), d->mediaPlayer, SLOT(pause()));
connect(ui.videoUrlEdit, SIGNAL(editingFinished()), this, SLOT(sourceChanged()));
connect(d->mediaPlayer, SIGNAL(error()), this, SLOT(stateChanged()));
connect(d->mediaPlayer, SIGNAL(stateChanged), this, SLOT(stateChanged()));
}
VideoTest::~VideoTest()
{
delete d;
}
void VideoTest::sourceChanged()
{
d->reply = d->networkAccessManager->get(QNetworkRequest(ui.videoUrlEdit->text()));
if(d->reply)
{
connect(d->reply, SIGNAL(readyRead()), this, SLOT(networkRequestReady()));
}
}
void VideoTest::stateChanged()
{
QString text = ui.textEdit->toPlainText();
text.append("\n").append(d->mediaPlayer->errorString()).append(" : ").append(d->mediaPlayer->mediaStatus());
ui.textEdit->setText(text);
}
void VideoTest::networkRequestReady()
{
d->mediaPlayer->setMedia(QMediaContent(), d->reply);
}
videotest.h
#ifndef VIDEOTEST_H
#define VIDEOTEST_H
#include <QtWidgets/QMainWindow>
#include "ui_videotest.h"
class VideoTest : public QMainWindow
{
Q_OBJECT
public:
VideoTest(QWidget *parent = 0);
~VideoTest();
public slots:
void sourceChanged();
void stateChanged();
void networkRequestReady();
private:
Ui::VideoTestClass ui;
struct Private;
Private * d;
};
#endif // VIDEOTEST_H
I found a way to make it work.
I gave up on Qt. The guys at Qt were insistent that it should work, but were unable to produce any configuration that works. They said that it should work if you stream from VLC, but I didn't get it to work. I also tried ffmpeg, ffserver and nginx rtmp streaming. I got these things working with mplayer, ffplay, VLC and some even with Windows Media Player, but never QMediaPlayer.
I tried to just give the URL to setMedia.
I tried to make a custom QIODevice to read the stream data and give that data to QMediaPlayer which was initialized with StreamPlayback, but it just would not succeed in reading the data.
In the end, all I needed was something to play a stream, is a QWidget and isn't GPL licensed.
I used libVLC and vlc-qt both of which work wonderfully.
Following these instructions was easy, but you need to remember to copy the header files from vlc-qt/windows/vlc_headers/2.2/ to vlc/sdk/include/vlc/plugins (sic). This is important, if you don't do this you might get errors during compilation. Note that these paths might be different if you have different versions of your platform doesn't match mine. Also, it might not be necessary when you read this.
VideoTest.h
#ifndef VIDEOTEST_H_
#define VIDEOTEST_H_
#include <QtWidgets/QMainWindow>
#include "ui_videotest.h"
class VideoTest: public QMainWindow
{
Q_OBJECT
public:
VideoTest(QWidget * p_parent = 0);
~VideoTest();
public slots:
void sourceChanged();
private:
struct Private;
Private * d;
Ui::VideoTestClass ui;
};
#endif
videotest.cpp
#include "videotest.h"
#include <vlc-qt/Common.h>
#include <vlc-qt/Instance.h>
#include <vlc-qt/Media.h>
#include <vlc-qt/MediaPlayer.h>
#include <vlc-qt/WidgetVideo.h>
struct VideoTest::Private
{
VlcInstance * vlcInstance;
VlcMediaPlayer * vlcMediaPlayer;
VlcMedia * vlcMedia;
VlcWidgetVideo * vlcVideoWidget;
};
VideoTest::VideoTest(QWidget * p_parent)
{
d = new Private();
ui.setupUi(this);
d->vlcMedia = 0;
d->vlcInstance = new VlcInstance(VlcCommon::args(), this);
d->vlcMediaPlayer = new VlcMediaPlayer(d->vlcInstance);
d->vlcVideoWidget = new VlcWidgetVideo(this);
d->vlcMediaPlayer->setVideoWidget(d->vlcVideoWidget);
d->vlcVideoWidget->setMediaPlayer(d->vlcMediaPlayer);
ui.videoLayout->addWidget(d->vlcVideoWidget);
connect(ui.playButton, SIGNAL(clicked()), d->vlcMediaPlayer, SLOT(play()));
connect(ui.pauseButton, SIGNAL(clicked()), d->vlcMediaPlayer, SLOT(pause()));
connect(ui.videoUrlEdit, SIGNAL(editingFinished()), this, SLOT(sourceChanged()));
}
VideoTest::~VideoTest()
{
delete d->vlcInstance;
delete d->vlcMediaPlayer;
delete d->vlcMedia;
delete d;
}
VideoTest::sourceChanged()
{
QUrl url(ui.videoUrlEdit->test());
if(url.isValid() == false)
{
return;
}
d->vlcMediaPlayer->stop();
delete d->vlcMedia;
d->vlcMedia = new VlcMedia(url.toString(), d->vlcInstance);
d->vlcMediaPlayer->open(d->vlcMedia);
}
VideoTest.ui
Make your own, I don't work for you :D
Just make sure that it has pauseButton, playButton, videoUrlEdit(QLineEdit) and videoLayout where the video widget will be inserted.
I've just managed to play stream in QML VideoOutput with C++ QMediaPlayer using the setMedia(QUrl("http://127.0.0.1:8080"));
The stream was created by VLC media player using the HTTP to the 8080 port. I've also succeeded in playing the stream created by VLC media player to local file by passing it to QMediaPlayer via setMedia(QMediaContent(), &localFile);.