【发布时间】:2016-02-15 19:05:22
【问题描述】:
我有以下
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();
一切正常,除了当我关闭弹出的 QVideoWidget 窗口时,视频会在某处继续播放,或者至少声音会继续播放。我认为连接线可以解决问题,但事实并非如此。关闭QVideoWidget窗口时停止播放的正确方法是什么?
【问题讨论】: