How to add Qvideowidget to second mainwindow
-
Put a layout on that widget and add your video player to it.
-
@SGaist it works but unfortunately that was not what i was thinking about,
int main(int argc, char *argv[]) { QApplication a(argc, argv); QApplication1 w; QVideoWidget vw(&w); vw.setGeometry(20, 20, 120, 140); QMediaPlayer * mp = new QMediaPlayer(&w); QString videoname = QFileDialog::getOpenFileName( &w,"choose video file", QDir::homePath()); mp->setMedia(QUrl::fromLocalFile(videoname)); mp->setVideoOutput(&vw); mp->play(); w.setCentralWidget(&vw); w.show(); return a.exec(); } with the code above, i just create an object of the main class and i passed the Qvideowidget to it but i cant do same to the other class... so this code adds the Qvideowidget to the main Window form.. i dont know if am been understood
-
Why don't you create that QVideoWidget directly in that second MainWindow ?
By the way, did you really named your class
QApplication1
? If so, that's a very bad idea. -
Then go to the constructor of that class and add your video widget related code there.
Even if nothing serious you should rather use FooClass than deriving names from one of Qt's own classes. You would be surprise by how fast things get serious when developing.
-
Did you set your video player in a layout that you set on your secondary MainWindow all within the constructor of that class ?
-
Did you do exactly how I suggested you to do ?
Can you show the actual code you are using ?
-
@SGaist thanks for your time, this are the code
QWidget *window = new QWidget; QFormLayout *layout = new QFormLayout; QVideoWidget * vw = new QVideoWidget(); QMediaPlayer * mp = new QMediaPlayer(vw); QPushButton *PAUSE = new QPushButton("Pause"); QString vidstring = QFileDialog::getOpenFileName(this, "Select video file", QDir::homePath()); //layout->addWidget(PAUSE); mp->setMedia(QUrl::fromLocalFile(vidstring)); mp->setVideoOutput(vw); layout->addWidget(vw); vw->setGeometry(100, 100, 500, 500); vw->show(); vw->setAttribute(Qt::WA_DeleteOnClose); window->setLayout(layout); mp->play(); window->show();
-
i tried this and it worked i made the QVideowidget the child of the second window and it worked...
QVideoWidget *vw = new QVideoWidget() ; QMediaPlayer * mp = new QMediaPlayer(vw); QString vidstring = QFileDialog::getOpenFileName(this, "Select video file", QDir::homePath()); mp->setMedia(QUrl::fromLocalFile(vidstring)); mp->setVideoOutput(vw); vw->setGeometry(100, 100, 500, 500); vw->setParent(this); vw->show(); mp->play(); }