Cannot add widgets to layout
-
Can you try give it parent?
VlcWidgetVideo* videoWidget = new VlcWidgetVideo(this); -
QWidget * central = new QWidget(this); QVBoxLayout * layout = new QVBoxLayout(central); this->setCentralWidget(central); VlcWidgetVideo* videoWidget = new VlcWidgetVideo(player, central); // And so on
I'm pretty sure this is redundant:
videoWidget->setMediaPlayer(player->mediaPlayer()); player->mediaPlayer()->setVideoWidget(videoWidget);
And this, should give you a segfault (or at least should not work):
list->addMedia(&VlcMedia("media.mp4",true,ins));
You can't pass pointers to temporaries!
-
@kshegunov Ok so it still does not work. But I just noticed that this works with VlcMediaPlayer but not with VlcMediaListPlayer .
-
You should read the documentation carefully:
https://vlc-qt.tano.si/reference/git/classVlcMediaListPlayer.html
A basic MediaListPlayer manager for VLC-Qt library. It provides internal playlist support. Requires a valid VlcMediaPlayer.
-
@kshegunov I have updated the code. But still not working .
-
@AyushExel204 said:
I have updated the code. But still not working .
You should rather say what is not working exactly, is it the original issue. And please post the updated code, as we are now in guessing mode what you updated.
-
@kshegunov i have updated the code and posted it in question statement. The multi window problem still exists. Video widget and main window widget are displayed separately.
-
@AyushExel204 said:
i have updated the code and posted it in question statement.
You mean you updated the original post? If that's so, please don't do it like that. There are two reasons against it - it's harder to track down what was changed, but more importantly if someone has a similar problem he/she won't be able to see the full history of how it was resolved. I suggest just posting the changes in your replies, or even the whole updated code.
Video widget and main window widget are displayed separately.
I see. What about the other issues others (and I among them) pointed out. For example giving parents to the widgets.
For example:VlcWidgetVideo* videoWidget = new VlcWidgetVideo(mediaplayer,this);
I think should rather be:
VlcWidgetVideo* videoWidget = new VlcWidgetVideo(mediaplayer, centralWidget());
which also implies you would have to set the central widget before creating the video widget. Also stripping down everything that's not necessary for the widget might help in tracking down the problem. Try a simpler constructor:
MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent) { QWidget * central = new QWidget(this); QVBoxLayout * layout = new QVBoxLayout(central); setCentralWidget(central); VlcInstance * vlc = new VlcInstance(QStringList()); VlcWidgetVideo * videoWidget = new VlcWidgetVideo(central); layout->addWidget(videoWidget); }
Kind regards.
-
@kshegunov I rewrote the code :
QWidget * central = new QWidget(this); QVBoxLayout * layout = new QVBoxLayout(central); setCentralWidget(central); VlcInstance *ins = new VlcInstance(QStringList()); VlcMediaPlayer* mediaplayer = new VlcMediaPlayer(ins); VlcMediaListPlayer* player= new VlcMediaListPlayer(mediaplayer,ins); VlcWidgetVideo* videoWidget = new VlcWidgetVideo(central); mediaplayer->setVideoWidget(videoWidget); videoWidget->setMediaPlayer(mediaplayer); VlcMediaList* list = new VlcMediaList(ins); list->addMedia(&VlcMedia("media.mp4",true,ins)); player->setMediaList(list); layout->addWidget(videoWidget); player->play();
Is it correct ? Its still has the same problem .
-
@AyushExel204
Yes, with the exception of this line:list->addMedia(&VlcMedia("media.mp4",true,ins));
it looks correct. It is strange that the widget will not allow to be added to a layout.
-
@kshegunov whats more strange is that video widget is allowed to ne added to layout while using VlcMediaPlayer but not while using VlcMediaListPlayer
-
@AyushExel204
It is indeed strange. I haven't worked with that library, but I see no good reason that is should work withVlcMediaPlayer
but not withVlcMediaListPlayer
. In this example (graciously provided by @mrjj over chat), they don't seem to useVlcMediaListPlayer
and as you said that should work. Perhaps you can use it to build upon. Also you might want to search through the library's bugtracker to see if there is something known about this issue.