⚠️ Forum Maintenance: Feb 6th, 8am - 14pm (UTC+2)

listView click start mp3 or video with default player (Windows)?

  • I try to figure out how to start a music or video file with the system default player installed on Windows. From the command line i can do that like

    start "" "c:\path to my\video file.avi"

    But it won't work from inside Qt. Well, at least not for me. Here is my code:

    void MainWindow::on_listView1_doubleClicked(const QModelIndex &index)
        QString file = filemodel->data(index, Qt::DisplayRole).toString();
        QString startMe = "C:/player/vlc.exe \"" + dirmodel->rootPath() + "/" + file + "\"";
        QProcess *startVideo = new QProcess();

    The code shows my successful attempt to start it with VLC. And this one was my system call.

    QString startMe = "start \"""\" \"" + dirmodel->rootPath() + "/" + file + "\"";


  • @qDebug
    Another way would be with QDesktopServices::openUrl(). This opens the file with the program that is defined as systems default. Should work with windows too (sorry i do not use windows :) )

  • @qDebug
    Agree with @the_ QDesktopServices::openUrl() is the way this should be done and I can confirm it works. In order to make sure video is opened in VLC you can set default program for video files as VLC player.

  • Thank you!

    QString file = filemodel->data(index, Qt::DisplayRole).toString();

    Works perfekt! :D