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)?
Forum Updated to NodeBB v4.3 + New Features

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 1 Watching
  • 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 8 Feb 2016, 02:23 last edited by qDebug 2 Aug 2016, 02:24
    #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.

    T 1 Reply Last reply 8 Feb 2016, 10:58
    0
    • Q qDebug
      8 Feb 2016, 02:23

      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.

      T Offline
      T Offline
      the_
      wrote on 8 Feb 2016, 10:58 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 8 Feb 2016, 15:12 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 8 Feb 2016, 15:58 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

          1/4

          8 Feb 2016, 02:23

          • Login

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