How to save pls file in QMediaPlaylist instead of m3u - c++

Actually, I try in QTCreator to save a playlist into a multitude of format.
QTCreator save and load without problems the m3u format.
It either load a .pls file I written by hand, but it can't save a similar pls format (It create an empty "playlst.pls").
I used the example showed from this manual:
http://doc.qt.io/qt-5/qmediaplaylist.html#save
The code save the playlist in pls format, the file is created, but empty.
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
// Player setting
player = new QMediaPlayer;
connect(player, SIGNAL(positionChanged(qint64)),
this, SLOT(positionChanged(qint64)));
player->setMedia(QUrl::fromLocalFile("/home/batfly/MilkyWay.mp3"));
player->setVolume(50);
player->play();
// Configure playlist:
playlist = new QMediaPlaylist;
playlist->addMedia(QUrl("file:///home/batfly/MilkyWay.mp3"));
playlist->addMedia(QUrl("file:///home/batfly/Gurdil.mp3"));
playlist->addMedia(QUrl("file:///home/batfly/OwenWasHere.mp3"));
playlist->setCurrentIndex(1);
// Set playlist on player:
player = new QMediaPlayer;
player->setPlaylist(playlist);
// Save playlist:
playlist->save(QUrl::fromLocalFile
("/home/batfly/playlisttest.pls"),"pls");
videoWidget = new QVideoWidget;
player->setVideoOutput(videoWidget);
videoWidget->show();
player->play();
}
Where is the problem?
QTCreator can't save into pls format, or I forget something?
Thank you!
PS: I add more information about my problem:
- I'm working in Linux (Debian 9.X).
- I use QTCreator 4.2, the last version have some bugs actually, so I don't update and keel the apt install version of Debian.

Related

QtListWidgetItem with Pixmap crashes if to many

I'm a noob, so sorry if my question feels dumb.
I use Qt Creator to make a kind of image viewer.
I added a QListWidget and added items with a pixmap. So far, so good.
Now I try to read the hole directory and add all 438 images.
The app crashes with this message:
Cn::Process::NotifyOutOfMemory(). 17:47:36: The program has
unexpectedly finished. 17:47:36: The process was ended forcefully.
If I reduce the count to 85. The app opens, but does only show 77 images.
I tried to fix this by changing addItem to addItems but don't know how to get the QListWidgetItem in a QList or on any other way. And than it is the question of this is a solution.
Can someone give me a kick in the right direction?
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
QDir dir("C:/");
QStringList items; // String???
foreach(QFileInfo var, dir.entryInfoList ()){
if(var.isFile ()){
//items += // What to do here ??
ui->listWidget->addItem (new QListWidgetItem(QPixmap(var.absoluteFilePath ()), var.fileName ()));
}
ui->listWidget->addItems (items);
}
}
Michael

Resizing web page inside a spliter in qt

My question is simple, but I have been struggling to find the solution. I have the QMainWindow showed in the image, constructed in the QtCreator.
I want to load an html web page in the QWidget csWindow, for that I have placed a Qlabel label_pic where I load my web Page. This is code so far:
MainWindow::MainWindow(QWidget *parent, Project *project) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
this->project = project;
QWebEngineView *view = new QWebEngineView(ui->label_pic);
view->load(QUrl("http://localhost/myWeb.html"));
////works fine, for an image
//QPixmap pix(":/img/imgs/someImage.png");
//ui->label_pic->setPixmap(pix);
//I also can load the web page in the QWidget csWindow but with the same result
//QWebEngineView *view = new QWebEngineView(ui->csWindow);
//view->load(QUrl("http://localhost/myWebb.html"));
}
The page loads fine but it does not fit into the corresponding space, It is created with a fixed size and never resize. I want the web page to be resized when I move the spliters, but I have not succed doing it.
I have tried several approaches, first just put an image in label_pic, enable the property scaled contents and works fine. Now, I want to do the same with the web page.
Thanks in advance.
The page loads fine but it does not fit into the corresponding space
This is because the size of the QWebEngineView is not know until it completes loading, so what you need is to connect to its signal loadFinished and resize label_pic :
connect(view, &QWebEngineView::loadFinished, [this]() {this->ui->label_pic->resize(this->ui->csWindow->size());});
I want the web page to be resized when I move the splitters
Then also you need to connect to signal QSplitter::splitterMoved from all your splitters and resize both csWindow and label_pic like this:
connect(ui->splitter, &QSplitter::splitterMoved, [this]() { this->view->resize(this->ui->csWindow->size()); this->ui->label_pic->resize(this->ui->csWindow->size());});
connect(ui->splitter_2, &QSplitter::splitterMoved, [this]() { this->view->resize(this->ui->csWindow->size()); this->ui->label_pic->resize(this->ui->csWindow->size());});
connect(ui->splitter_3, &QSplitter::splitterMoved, [this]() { this->view->resize(this->ui->csWindow->size()); this->ui->label_pic->resize(this->ui->csWindow->size());});
and note that this would work best if you set a layout for your window, either from designer or adding code, for instance:
QGridLayout *layout = new QGridLayout;
layout->addWidget(ui->splitter_3);
this->ui->centralWidget->setLayout(layout);
and remember you should make all connect statements before you load the view.

Qt : issue for displaying IP-CAMERA stream

I'm develop a Qt app for displaying my IP-CAMERA stream. It has code similar to this project :
https://github.com/cleitonbueno/qt-rtsp-test/tree/widgets
QVideoWidget *_vw1 = new QVideoWidget;
QMediaPlayer *_player1 = new QMediaPlayer;
QGridLayout *layout = new QGridLayout;
layout->addWidget(_vw1,0,0,1,1);
QWidget *win = new QWidget();
win->setLayout(layout);
setCentralWidget(win);
_player1->setVideoOutput(_vw1);
const QUrl url1 = QUrl("rtsp://184.72.239.149/vod/mp4:BigBuckBunny_115k.mov");
const QNetworkRequest requestRtsp1(url1);
_player1->setMedia(requestRtsp1);
_player1->play();
When i play Bigbuckbunny video, video's packet is coming and media player plays. But When i write ip camera's rtsp address in Qurl, Media player can't play this stream.
Capture made with Wireshark shows that the rtsp packets are received. But media player is seen black screen.
I'm using linux ubuntu 16.04 Gnome 3 (86_64 GNU/Linux)
QT 5.10.0
QT creator is 4.5
I remove ip camera's username and password. But I also tried with username and password (rtsp://192.168.1.1:554/live/stream1 && rtsp://username:password#192.168.1.1:554/live/stream1).
Can you please help me. I can't understand the root cause of this problem.

How to download files from QWebView?

I created a small web browser with QT Creator and QWebView. I's working very good and the pages are loading very fast. But how can I make my browser capable of downloading files? I looked through the signals and functions list, but I did't find something that could help me.
How can I found out if a QUrl contains a link to a file other than text/html so I can download it?
QWebView has a 'QWebPage' member which you can access it's pointer with webView.page() . This is where you should look. QWebPage has two signals: downloadRequested(..) and unsupportedContent(..). I believe dowloadRequest is only emitted when user right clicks a link and selects 'Save Link' and unsupportedContent is emitted when target URL cannot be shown (not an html/text).
But for unsupportedContent to be emitted, you should set forwardUnsupportedContent to True with function webPage.setForwardUnsupportedContent(true). Here is a minimal example I have created:
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
ui->webView->page()->setForwardUnsupportedContent(true);
connect(ui->webView->page(),SIGNAL(downloadRequested(QNetworkRequest)),this,SLOT(download(QNetworkRequest)));
connect(ui->webView->page(),SIGNAL(unsupportedContent(QNetworkReply*)),this,SLOT(unsupportedContent(QNetworkReply*)));
}
MainWindow::~MainWindow()
{
delete ui;
}
void MainWindow::download(const QNetworkRequest &request){
qDebug()<<"Download Requested: "<<request.url();
}
void MainWindow::unsupportedContent(QNetworkReply * reply){
qDebug()<<"Unsupported Content: "<<reply->url();
}
Remember, MainWindow::download(..) and MainWindow::unsupportedContent(..) are SLOTs !

Qt QLabel default text

My code is very simple:
Widget::Widget(QWidget *parent) : QWidget(parent), ui(new Ui::Widget)
{
lineEdit = new QLineEdit();
label = new QLabel("");
connect(lineEdit, SIGNAL(textChanged(QString)), label, SLOT(setText(QString)));
ui->setupUi(this);
}
I compiled it, and no error or warning.
But When I run it, The UI like this:
Why QLabel's default text was TextLabel?
You should read some tutorials from Qt docs. You're mixing QtDesigner ui with manual widget creation. Your default text on label comes from your ui file. Also you don't need to create your labels/line edits when you use ui file. Just get them stright from ui class. So if you'll get your ui file back to normal, then you may do something like this:
Widget::Widget(QWidget *parent) : QWidget(parent), ui(new Ui::Widget)
{
ui->setupUi(this);
connect(ui->lineEdit, SIGNAL(textChanged(QString)), ui->label, SLOT(setText(QString)));
}
Also change text in your label with Qt Designer by doubleclick on it.
That's because both your
lineEdit = new QLineEdit();
label = new QLabel("");
are different that the ones you created in your ui. You are defining two new widgets, while you should probably reference the previous ones:
ui->lineEdit->clear();
ui->label->clear();
connect(ui->line....
//etc...