Important: Please read the Qt Code of Conduct -

Trying to play video with qmediaplayer and qvideowidget

  • Hi,

    Im trying to play a video with a QMediaPlayer and a QVideoWidget. I have just a MainWindow with member variables :
    QVideoWidget *_video;
    QMediaPlaplyer *_player;
    QMediaPlaylist *_playlist;

    and this in the mainwindow.cpp :

    MainWindow::MainWindow(QWidget *parent) :
    ui(new Ui::MainWindow)

    _player = new QMediaPlayer(this);
    _video = new QVideoWidget(this);
    _playlist = new QMediaPlaylist(this);
    QUrl    url = QUrl::fromLocalFile("C:\Users\*****\Downloads\Despicable Me (2010) [1080p]\test.mp4");
    std::cout << "C'est valide " << url.isValid() << std::endl;

    // _test = new QWidget(this);
    // _test->setStyleSheet("background: blue;");

    When i try to display a simple QWidget _test with a blue background it displays it, but it doesnt work with the QVideoWidget. The url is valid and I just want to play the video.

    Does anyone have a suggestion ?

  • Lifetime Qt Champion


    Your path is wrong, either use double backslashes to escape the slash properly or do it the Qt way and use forward slashes.

  • @SGaist

    Indeed it works, I thought it was okey with the QUrl isValid returning true.

    Thank you !

  • Lifetime Qt Champion

    A valid URL doesn't mean that it points to something valid ;)

    You're welcome !

    Since you have it working now, please mark the thread as solved using the "Topic Tool" button so other forum users may know a solution has been found :)

Log in to reply