Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Solved QVideoWidget stand alone. How to stop video when window closes?

    General and Desktop
    1
    2
    426
    Loading More Posts
    • 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.
    • P
      phirestalker last edited by

      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?

      1 Reply Last reply Reply Quote 0
      • P
        phirestalker last edited by

        just had to add

        vw->setAttribute( Qt::WA_DeleteOnClose );
        
        1 Reply Last reply Reply Quote 1
        • First post
          Last post