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

Cannot add widgets to layout

Scheduled Pinned Locked Moved Unsolved General and Desktop
qlayoutqwidgetqmainwindowvlc-qt
18 Posts 5 Posters 10.4k 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.
  • A AyushExel204
    27 May 2016, 06:17

    @JohanSolo Not working .

    R Offline
    R Offline
    Ratzz
    wrote on 27 May 2016, 06:37 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.

    A 1 Reply Last reply 27 May 2016, 06:49
    0
    • R Ratzz
      27 May 2016, 06:37

      @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);
      A Offline
      A Offline
      AyushExel204
      wrote on 27 May 2016, 06:49 last edited by
      #5

      @Ratzz Yeah

      1 Reply Last reply
      0
      • J Offline
        J Offline
        JohanSolo
        wrote on 27 May 2016, 06:55 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
        • M Offline
          M Offline
          mrjj
          Lifetime Qt Champion
          wrote on 27 May 2016, 07:06 last edited by
          #7

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

          1 Reply Last reply
          0
          • A AyushExel204
            27 May 2016, 05:52
            
            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 ?

            K Offline
            K Offline
            kshegunov
            Moderators
            wrote on 27 May 2016, 07:07 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

            A 1 Reply Last reply 27 May 2016, 07:55
            0
            • K kshegunov
              27 May 2016, 07:07

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

              A Offline
              A Offline
              AyushExel204
              wrote on 27 May 2016, 07:55 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 .

              K 1 Reply Last reply 27 May 2016, 07:58
              0
              • A AyushExel204
                27 May 2016, 07:55

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

                K Offline
                K Offline
                kshegunov
                Moderators
                wrote on 27 May 2016, 07:58 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

                A 1 Reply Last reply 27 May 2016, 08:14
                0
                • K kshegunov
                  27 May 2016, 07:58

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

                  A Offline
                  A Offline
                  AyushExel204
                  wrote on 27 May 2016, 08:14 last edited by
                  #11

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

                  K 1 Reply Last reply 27 May 2016, 08:30
                  0
                  • A AyushExel204
                    27 May 2016, 08:14

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

                    K Offline
                    K Offline
                    kshegunov
                    Moderators
                    wrote on 27 May 2016, 08:30 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
                    • A Offline
                      A Offline
                      AyushExel204
                      wrote on 27 May 2016, 08:57 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.

                      K 1 Reply Last reply 27 May 2016, 10:24
                      0
                      • A AyushExel204
                        27 May 2016, 08:57

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

                        K Offline
                        K Offline
                        kshegunov
                        Moderators
                        wrote on 27 May 2016, 10:24 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

                        A 1 Reply Last reply 27 May 2016, 14:52
                        0
                        • K kshegunov
                          27 May 2016, 10:24

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

                          A Offline
                          A Offline
                          AyushExel204
                          wrote on 27 May 2016, 14:52 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 .

                          K 1 Reply Last reply 27 May 2016, 18:15
                          0
                          • A AyushExel204
                            27 May 2016, 14:52

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

                            K Offline
                            K Offline
                            kshegunov
                            Moderators
                            wrote on 27 May 2016, 18:15 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
                            • A Offline
                              A Offline
                              AyushExel204
                              wrote on 27 May 2016, 18:41 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

                              K 1 Reply Last reply 27 May 2016, 18:48
                              0
                              • A AyushExel204
                                27 May 2016, 18:41

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

                                K Offline
                                K Offline
                                kshegunov
                                Moderators
                                wrote on 27 May 2016, 18:48 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

                                13/18

                                27 May 2016, 08:57

                                • Login

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