listView click start mp3 or video with default player (Windows)?
Solved
General and Desktop
-
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(); startVideo->start(startMe); }
The code shows my successful attempt to start it with VLC. And this one was my system call.
QString startMe = "start \"""\" \"" + dirmodel->rootPath() + "/" + file + "\"";
Thanks.