Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. listView click start mp3 or video with default player (Windows)?
QtWS25 Last Chance

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

Scheduled Pinned Locked Moved Solved General and Desktop
windowsmp3videoqprocess
4 Posts 3 Posters 1.9k Views
  • 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.
  • Q Offline
    Q Offline
    qDebug
    wrote on last edited by qDebug
    #1

    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.

    the_T 1 Reply Last reply
    0
    • Q qDebug

      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.

      the_T Offline
      the_T Offline
      the_
      wrote on last edited by
      #2

      @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 :) )

      -- No support in PM --

      1 Reply Last reply
      1
      • A Offline
        A Offline
        asanka424
        wrote on last edited by
        #3

        @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.

        1 Reply Last reply
        1
        • Q Offline
          Q Offline
          qDebug
          wrote on last edited by
          #4

          Thank you!

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

          Works perfekt! :D

          1 Reply Last reply
          0

          • Login

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • Users
          • Groups
          • Search
          • Get Qt Extensions
          • Unsolved