Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Cannot add widgets to layout
QtWS25 Last Chance

Cannot add widgets to layout

Scheduled Pinned Locked Moved Unsolved General and Desktop
qlayoutqwidgetqmainwindowvlc-qt
18 Posts 5 Posters 10.3k Views
  • 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.
  • AyushExel204A AyushExel204

    @JohanSolo Not working .

    RatzzR Offline
    RatzzR Offline
    Ratzz
    wrote on last edited by Ratzz
    #4

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

    AyushExel204A 1 Reply Last reply
    0
    • RatzzR 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);
      AyushExel204A Offline
      AyushExel204A Offline
      AyushExel204
      wrote on last edited by
      #5

      @Ratzz Yeah

      1 Reply Last reply
      0
      • JohanSoloJ Offline
        JohanSoloJ Offline
        JohanSolo
        wrote on last edited by
        #6

        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
        0
        • mrjjM Offline
          mrjjM Offline
          mrjj
          Lifetime Qt Champion
          wrote on last edited by
          #7

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

          1 Reply Last reply
          0
          • AyushExel204A 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 ?

            kshegunovK Offline
            kshegunovK Offline
            kshegunov
            Moderators
            wrote on last edited by kshegunov
            #8

            @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

            AyushExel204A 1 Reply Last reply
            0
            • kshegunovK 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!

              AyushExel204A Offline
              AyushExel204A Offline
              AyushExel204
              wrote on last edited by
              #9

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

              kshegunovK 1 Reply Last reply
              0
              • AyushExel204A AyushExel204

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

                kshegunovK Offline
                kshegunovK Offline
                kshegunov
                Moderators
                wrote on last edited by
                #10

                @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

                AyushExel204A 1 Reply Last reply
                0
                • kshegunovK kshegunov

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

                  AyushExel204A Offline
                  AyushExel204A Offline
                  AyushExel204
                  wrote on last edited by
                  #11

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

                  kshegunovK 1 Reply Last reply
                  0
                  • AyushExel204A AyushExel204

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

                    kshegunovK Offline
                    kshegunovK Offline
                    kshegunov
                    Moderators
                    wrote on last edited by
                    #12

                    @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
                    0
                    • AyushExel204A Offline
                      AyushExel204A Offline
                      AyushExel204
                      wrote on last edited by
                      #13

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

                      kshegunovK 1 Reply Last reply
                      0
                      • AyushExel204A AyushExel204

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

                        kshegunovK Offline
                        kshegunovK Offline
                        kshegunov
                        Moderators
                        wrote on last edited by kshegunov
                        #14

                        @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

                        AyushExel204A 1 Reply Last reply
                        0
                        • kshegunovK 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.

                          AyushExel204A Offline
                          AyushExel204A Offline
                          AyushExel204
                          wrote on last edited by
                          #15

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

                          kshegunovK 1 Reply Last reply
                          0
                          • AyushExel204A AyushExel204

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

                            kshegunovK Offline
                            kshegunovK Offline
                            kshegunov
                            Moderators
                            wrote on last edited by
                            #16

                            @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
                            0
                            • AyushExel204A Offline
                              AyushExel204A Offline
                              AyushExel204
                              wrote on last edited by
                              #17

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

                              kshegunovK 1 Reply Last reply
                              0
                              • AyushExel204A AyushExel204

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

                                kshegunovK Offline
                                kshegunovK Offline
                                kshegunov
                                Moderators
                                wrote on last edited by kshegunov
                                #18

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

                                • Login

                                • Login or register to search.
                                • First post
                                  Last post
                                0
                                • Categories
                                • Recent
                                • Tags
                                • Popular
                                • Users
                                • Groups
                                • Search
                                • Get Qt Extensions
                                • Unsolved