Solved QVideoWidget stand alone. How to stop video when window closes?
-
I have the following
QVideoWidget* vw = new QVideoWidget; QMediaResource mr(QUrl::fromLocalFile(item->data(Qt::UserRole + FilepathRole).toString())); QMediaContent mc(mr); QMediaPlayer* player = new QMediaPlayer; QObject::connect(vw,SIGNAL(destroyed(QObject*)),player,SLOT(stop())); player->setMedia(mc); player->setVideoOutput(vw); QRect rect = QApplication::desktop()->availableGeometry(); int width = vids[vids.indexOf(item->data(Qt::UserRole + FilepathRole).toString())].width; int height = vids[vids.indexOf(item->data(Qt::UserRole + FilepathRole).toString())].height; int x = (rect.width() / 2) - (width / 2); int y = (rect.height() / 2) - (height / 2); vw->setGeometry(x,y,width,height); vw->show(); player->play();
everything works except that when I close the window for the QVideoWidget that pops up the video keeps playing somewhere, or at least the sound does. I thought that connect line would do the trick but it does not. What is the correct way to stop playback when closing the QVideoWidget window?
-
just had to add
vw->setAttribute( Qt::WA_DeleteOnClose );