Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Update: Forum Guidelines & Code of Conduct


    Qt World Summit: Early-Bird Tickets

    Unsolved Cannot add widgets to layout

    General and Desktop
    qlayout qwidget qmainwindow vlc-qt
    5
    18
    8225
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • AyushExel204
      AyushExel204 last edited by AyushExel204

      
      MainWindow::MainWindow(QWidget *parent) :
          QMainWindow(parent)
      
      {
      
          VlcInstance *ins = new VlcInstance(QStringList());
          VlcMediaPlayer* mediaplayer = new VlcMediaPlayer(ins);
          VlcMediaListPlayer* player=  new VlcMediaListPlayer(mediaplayer,ins);
          VlcWidgetVideo* videoWidget = new VlcWidgetVideo(mediaplayer,this);
          VlcMediaList* list = new VlcMediaList(ins);
          list->addMedia(&VlcMedia("media.mp4",true,ins));
          player->setMediaList(list);
          QVBoxLayout* layout = new QVBoxLayout;
          layout->addWidget(videoWidget);
          this->setCentralWidget(new QWidget);
          this->centralWidget()->setLayout(layout);
          player->play();
      
      }
      

      When I run this code the video widget is displayed separately outside the main window dialog . How can this be fixed ?

      kshegunov 1 Reply Last reply Reply Quote 0
      • JohanSolo
        JohanSolo last edited by

        Well, try this:

        QWidget* dummy = new QWidget();
        dummy->setLayout( layout );
        this->setCentralWidget( dummy );
        

        `They did not know it was impossible, so they did it.'
        -- Mark Twain

        AyushExel204 1 Reply Last reply Reply Quote 0
        • AyushExel204
          AyushExel204 @JohanSolo last edited by

          @JohanSolo Not working .

          Ratzz 1 Reply Last reply Reply Quote 0
          • Ratzz
            Ratzz @AyushExel204 last edited by Ratzz

            @AyushExel204
            did you add videoWidget to layout like this?

                QVBoxLayout* layout = new QVBoxLayout;
                layout->addWidget(videoWidget);
                QWidget *window = new QWidget();
                window->setLayout(layout);
                this->setCentralWidget(window);

            --Alles ist gut.

            AyushExel204 1 Reply Last reply Reply Quote 0
            • AyushExel204
              AyushExel204 @Ratzz last edited by

              @Ratzz Yeah

              1 Reply Last reply Reply Quote 0
              • JohanSolo
                JohanSolo last edited by

                Those two lines:

                videoWidget->setMediaPlayer(player->mediaPlayer());
                player->mediaPlayer()->setVideoWidget(videoWidget);
                

                seem a bit circular to me... But most probably not the reason why it's not working.

                `They did not know it was impossible, so they did it.'
                -- Mark Twain

                1 Reply Last reply Reply Quote 0
                • mrjj
                  mrjj Lifetime Qt Champion last edited by

                  Can you try give it parent?
                  VlcWidgetVideo* videoWidget = new VlcWidgetVideo(this);

                  1 Reply Last reply Reply Quote 0
                  • kshegunov
                    kshegunov Moderators @AyushExel204 last edited by kshegunov

                    @AyushExel204

                        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!

                    Read and abide by the Qt Code of Conduct

                    AyushExel204 1 Reply Last reply Reply Quote 0
                    • AyushExel204
                      AyushExel204 @kshegunov last edited by

                      @kshegunov Ok so it still does not work. But I just noticed that this works with VlcMediaPlayer but not with VlcMediaListPlayer .

                      kshegunov 1 Reply Last reply Reply Quote 0
                      • kshegunov
                        kshegunov Moderators @AyushExel204 last edited by

                        @AyushExel204

                        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.

                        Read and abide by the Qt Code of Conduct

                        AyushExel204 1 Reply Last reply Reply Quote 0
                        • AyushExel204
                          AyushExel204 @kshegunov last edited by

                          @kshegunov I have updated the code. But still not working .

                          kshegunov 1 Reply Last reply Reply Quote 0
                          • kshegunov
                            kshegunov Moderators @AyushExel204 last edited by

                            @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.

                            Read and abide by the Qt Code of Conduct

                            1 Reply Last reply Reply Quote 0
                            • AyushExel204
                              AyushExel204 last edited by

                              @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.

                              kshegunov 1 Reply Last reply Reply Quote 0
                              • kshegunov
                                kshegunov Moderators @AyushExel204 last edited by kshegunov

                                @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.

                                Read and abide by the Qt Code of Conduct

                                AyushExel204 1 Reply Last reply Reply Quote 0
                                • AyushExel204
                                  AyushExel204 @kshegunov last edited by

                                  @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 .

                                  kshegunov 1 Reply Last reply Reply Quote 0
                                  • kshegunov
                                    kshegunov Moderators @AyushExel204 last edited by

                                    @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.

                                    Read and abide by the Qt Code of Conduct

                                    1 Reply Last reply Reply Quote 0
                                    • AyushExel204
                                      AyushExel204 last edited by

                                      @kshegunov whats more strange is that video widget is allowed to ne added to layout while using VlcMediaPlayer but not while using VlcMediaListPlayer

                                      kshegunov 1 Reply Last reply Reply Quote 0
                                      • kshegunov
                                        kshegunov Moderators @AyushExel204 last edited by kshegunov

                                        @AyushExel204
                                        It is indeed strange. I haven't worked with that library, but I see no good reason that is should work with VlcMediaPlayer but not with VlcMediaListPlayer. In this example (graciously provided by @mrjj over chat), they don't seem to use VlcMediaListPlayer 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.

                                        Read and abide by the Qt Code of Conduct

                                        1 Reply Last reply Reply Quote 0
                                        • First post
                                          Last post