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. Audio duration for file manager

Audio duration for file manager

Scheduled Pinned Locked Moved Unsolved General and Desktop
20 Posts 4 Posters 1.8k 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.
  • N Offline
    N Offline
    Nemooo
    wrote on last edited by Nemooo
    #1

    Hello!
    I tried to get audio data (duration) for my file manager without using phonon. It is possible to write only for one file. However in console I get all durations from directory.

    Here is the part of my code where I am trying to get the data. How to get those datas for all files in the directory?

      void MainWindow::CreateTable(const QString & p) {
      filemodel->removeRows( 0, filemodel->rowCount() );
    
    
    filemodelcurrentdir = QDir(p).path();
    files = QDir(p).entryInfoList(QDir::Dirs | QDir::Files | QDir::NoDotAndDotDot);
    foreach(const QFileInfo &fi, files) {
        QString name = QString("%0").arg(fi.fileName());
        filemodel->insertRow(0);
        if (fi.isDir()) {
            filemodel->setData(filemodel->index(0, 0), name);
            filemodel->setData(filemodel->index(0, 0), dirIcon, Qt::DecorationRole);
        } else {
            filemodel->setData(filemodel->index(0, 0), name);
            filemodel->setData(filemodel->index(0, 0), fileIcon, Qt::DecorationRole);
            }
        filemodel->setData(filemodel->index(0, 1), size_human(fi.size()));
    
       QMediaPlayer* player = new QMediaPlayer();
    
        player->setMedia(QUrl::fromLocalFile(filemodelcurrentdir + "/" + name));
    
        double dura;
    
        connect(player, &QMediaPlayer::durationChanged, this, [&](qint64 dur) {
            dura = static_cast<double>(dur)/60000.0;
                  qDebug() << "duration = " << dura;
        });
    
        filemodel->setData(filemodel->index(0, 2), QString().setNum(dura));
        delete player;
    
    
    }
    
    
    filemodel->setHeaderData(0,Qt::Horizontal,QObject::tr("Name" ));
    filemodel->setHeaderData(1,Qt::Horizontal,QObject::tr("Size" ));
    filemodel->setHeaderData(2,Qt::Horizontal,QObject::tr("Duration" ));
    
    pTreeView2->setSortingEnabled(true);
    pTreeView2->setColumnWidth(0, 300);
    pTreeView2->setColumnWidth(1, 100);
    pTreeView2->setColumnWidth(2, 100);
    
      }
    

    Thank you very much!

    jsulmJ 1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

      Something is not clear with your question. On one side you state that you want to do it for only one file and then for all files in a folder.

      What is the case that you want to achieve ?

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      0
      • N Offline
        N Offline
        Nemooo
        wrote on last edited by
        #3

        I want to do this for all files in the folder. I want to see in the 3rd column the duration of the audio files. The written code only does this for 1 file (added to the 3rd column). The duration of the remaining files in this column is 0. The console shows the duration of all files. I need the result not in the console but in the 3rd column.

        1 Reply Last reply
        0
        • N Nemooo

          Hello!
          I tried to get audio data (duration) for my file manager without using phonon. It is possible to write only for one file. However in console I get all durations from directory.

          Here is the part of my code where I am trying to get the data. How to get those datas for all files in the directory?

            void MainWindow::CreateTable(const QString & p) {
            filemodel->removeRows( 0, filemodel->rowCount() );
          
          
          filemodelcurrentdir = QDir(p).path();
          files = QDir(p).entryInfoList(QDir::Dirs | QDir::Files | QDir::NoDotAndDotDot);
          foreach(const QFileInfo &fi, files) {
              QString name = QString("%0").arg(fi.fileName());
              filemodel->insertRow(0);
              if (fi.isDir()) {
                  filemodel->setData(filemodel->index(0, 0), name);
                  filemodel->setData(filemodel->index(0, 0), dirIcon, Qt::DecorationRole);
              } else {
                  filemodel->setData(filemodel->index(0, 0), name);
                  filemodel->setData(filemodel->index(0, 0), fileIcon, Qt::DecorationRole);
                  }
              filemodel->setData(filemodel->index(0, 1), size_human(fi.size()));
          
             QMediaPlayer* player = new QMediaPlayer();
          
              player->setMedia(QUrl::fromLocalFile(filemodelcurrentdir + "/" + name));
          
              double dura;
          
              connect(player, &QMediaPlayer::durationChanged, this, [&](qint64 dur) {
                  dura = static_cast<double>(dur)/60000.0;
                        qDebug() << "duration = " << dura;
              });
          
              filemodel->setData(filemodel->index(0, 2), QString().setNum(dura));
              delete player;
          
          
          }
          
          
          filemodel->setHeaderData(0,Qt::Horizontal,QObject::tr("Name" ));
          filemodel->setHeaderData(1,Qt::Horizontal,QObject::tr("Size" ));
          filemodel->setHeaderData(2,Qt::Horizontal,QObject::tr("Duration" ));
          
          pTreeView2->setSortingEnabled(true);
          pTreeView2->setColumnWidth(0, 300);
          pTreeView2->setColumnWidth(1, 100);
          pTreeView2->setColumnWidth(2, 100);
          
            }
          

          Thank you very much!

          jsulmJ Offline
          jsulmJ Offline
          jsulm
          Lifetime Qt Champion
          wrote on last edited by jsulm
          #4

          @Nemooo said in Audio duration for file manager:

          filemodel->setData(filemodel->index(0, 2), QString().setNum(dura));

          You you should do this inside lambda connected to durationChanged, else dura will be 0.0 when you do:

          filemodel->setData(filemodel->index(0, 2), QString().setNum(dura));
          

          dura is changed when the slot is called, but you already use it just after calling connect.

          You have a memory leak (you don't delete QMediaPlayer instances you're creating in a loop!).

          https://forum.qt.io/topic/113070/qt-code-of-conduct

          N 1 Reply Last reply
          2
          • jsulmJ jsulm

            @Nemooo said in Audio duration for file manager:

            filemodel->setData(filemodel->index(0, 2), QString().setNum(dura));

            You you should do this inside lambda connected to durationChanged, else dura will be 0.0 when you do:

            filemodel->setData(filemodel->index(0, 2), QString().setNum(dura));
            

            dura is changed when the slot is called, but you already use it just after calling connect.

            You have a memory leak (you don't delete QMediaPlayer instances you're creating in a loop!).

            N Offline
            N Offline
            Nemooo
            wrote on last edited by
            #5

            @jsulm said in Audio duration for file manager:

            @Nemooo said in Audio duration for file manager:

            filemodel->setData(filemodel->index(0, 2), QString().setNum(dura));

            You you should do this inside lambda connected to durationChanged, else dura will be 0.0 when you do:

            filemodel->setData(filemodel->index(0, 2), QString().setNum(dura));
            

            dura is changed when the slot is called, but you already use it just after calling connect.

            You have a memory leak (you don't delete QMediaPlayer instances you're creating in a loop!).

            Thank you!
            I did this file inside lambda

            filemodel->setData(filemodel->index(0, 2), QString().setNum(dura));
            

            and still it doesn't work. I deleted QMediaPlayer, just erased this line by accident.

            jsulmJ 1 Reply Last reply
            0
            • N Nemooo

              @jsulm said in Audio duration for file manager:

              @Nemooo said in Audio duration for file manager:

              filemodel->setData(filemodel->index(0, 2), QString().setNum(dura));

              You you should do this inside lambda connected to durationChanged, else dura will be 0.0 when you do:

              filemodel->setData(filemodel->index(0, 2), QString().setNum(dura));
              

              dura is changed when the slot is called, but you already use it just after calling connect.

              You have a memory leak (you don't delete QMediaPlayer instances you're creating in a loop!).

              Thank you!
              I did this file inside lambda

              filemodel->setData(filemodel->index(0, 2), QString().setNum(dura));
              

              and still it doesn't work. I deleted QMediaPlayer, just erased this line by accident.

              jsulmJ Offline
              jsulmJ Offline
              jsulm
              Lifetime Qt Champion
              wrote on last edited by
              #6

              @Nemooo said in Audio duration for file manager:

              and still it doesn't work

              Probably because when the slot is called you already added another line on top...

              https://forum.qt.io/topic/113070/qt-code-of-conduct

              N 1 Reply Last reply
              0
              • jsulmJ jsulm

                @Nemooo said in Audio duration for file manager:

                and still it doesn't work

                Probably because when the slot is called you already added another line on top...

                N Offline
                N Offline
                Nemooo
                wrote on last edited by
                #7

                @jsulm said in Audio duration for file manager:

                @Nemooo said in Audio duration for file manager:

                and still it doesn't work

                Probably because when the slot is called you already added another line on top...

                I tried to change the order. First I called the slot, then I added lines. Still doesn't work.

                jsulmJ 1 Reply Last reply
                0
                • N Nemooo

                  @jsulm said in Audio duration for file manager:

                  @Nemooo said in Audio duration for file manager:

                  and still it doesn't work

                  Probably because when the slot is called you already added another line on top...

                  I tried to change the order. First I called the slot, then I added lines. Still doesn't work.

                  jsulmJ Offline
                  jsulmJ Offline
                  jsulm
                  Lifetime Qt Champion
                  wrote on last edited by
                  #8

                  @Nemooo said in Audio duration for file manager:

                  First I called the slot

                  You don't call the slot, the slot is called when the signal is emitted...

                  https://forum.qt.io/topic/113070/qt-code-of-conduct

                  N 1 Reply Last reply
                  1
                  • jsulmJ jsulm

                    @Nemooo said in Audio duration for file manager:

                    First I called the slot

                    You don't call the slot, the slot is called when the signal is emitted...

                    N Offline
                    N Offline
                    Nemooo
                    wrote on last edited by
                    #9

                    @jsulm
                    Ok! Yes, emitted signal - > slot called - > still doesn't work

                    jsulmJ 1 Reply Last reply
                    0
                    • N Nemooo

                      @jsulm
                      Ok! Yes, emitted signal - > slot called - > still doesn't work

                      jsulmJ Offline
                      jsulmJ Offline
                      jsulm
                      Lifetime Qt Champion
                      wrote on last edited by
                      #10

                      @Nemooo Just to clarify: you don't know when exactly the signal will be emitted. This is done by QMediaPlayer, not by you. So, you do not know in which order the signals will be emitted. It can work like you're doing. You should pass an additional parameter to the slot to tell it which line/index to update.

                      https://forum.qt.io/topic/113070/qt-code-of-conduct

                      N 1 Reply Last reply
                      0
                      • jsulmJ jsulm

                        @Nemooo Just to clarify: you don't know when exactly the signal will be emitted. This is done by QMediaPlayer, not by you. So, you do not know in which order the signals will be emitted. It can work like you're doing. You should pass an additional parameter to the slot to tell it which line/index to update.

                        N Offline
                        N Offline
                        Nemooo
                        wrote on last edited by
                        #11

                        @jsulm said in Audio duration for file manager:

                        @Nemooo Just to clarify: you don't know when exactly the signal will be emitted. This is done by QMediaPlayer, not by you. So, you do not know in which order the signals will be emitted. It can work like you're doing. You should pass an additional parameter to the slot to tell it which line/index to update.

                        Thank you! Could you please show me the example how to do it. I am new in Qt so I don't know how to do it.
                        Thank you!

                        jsulmJ 1 Reply Last reply
                        0
                        • N Nemooo

                          @jsulm said in Audio duration for file manager:

                          @Nemooo Just to clarify: you don't know when exactly the signal will be emitted. This is done by QMediaPlayer, not by you. So, you do not know in which order the signals will be emitted. It can work like you're doing. You should pass an additional parameter to the slot to tell it which line/index to update.

                          Thank you! Could you please show me the example how to do it. I am new in Qt so I don't know how to do it.
                          Thank you!

                          jsulmJ Offline
                          jsulmJ Offline
                          jsulm
                          Lifetime Qt Champion
                          wrote on last edited by
                          #12

                          @Nemooo Something like (not really Qt specific):

                          auto index = filemodel->index(0, 2);
                          connect(player, &QMediaPlayer::durationChanged, this, [this, index](qint64 dur) {
                                  dura = static_cast<double>(dur)/60000.0;
                                  qDebug() << "duration = " << dura;
                                  filemodel->setData(index, QString().setNum(dura));
                              });
                          

                          https://forum.qt.io/topic/113070/qt-code-of-conduct

                          N 1 Reply Last reply
                          3
                          • jsulmJ jsulm

                            @Nemooo Something like (not really Qt specific):

                            auto index = filemodel->index(0, 2);
                            connect(player, &QMediaPlayer::durationChanged, this, [this, index](qint64 dur) {
                                    dura = static_cast<double>(dur)/60000.0;
                                    qDebug() << "duration = " << dura;
                                    filemodel->setData(index, QString().setNum(dura));
                                });
                            
                            N Offline
                            N Offline
                            Nemooo
                            wrote on last edited by
                            #13

                            @jsulm said in Audio duration for file manager:

                            @Nemooo Something like (not really Qt specific):

                            auto index = filemodel->index(0, 2);
                            connect(player, &QMediaPlayer::durationChanged, this, [this, index](qint64 dur) {
                                    dura = static_cast<double>(dur)/60000.0;
                                    qDebug() << "duration = " << dura;
                                    filemodel->setData(index, QString().setNum(dura));
                                });
                            

                            Now I understand what you mean but it still doesn't work

                            aha_1980A jsulmJ 2 Replies Last reply
                            0
                            • N Nemooo

                              @jsulm said in Audio duration for file manager:

                              @Nemooo Something like (not really Qt specific):

                              auto index = filemodel->index(0, 2);
                              connect(player, &QMediaPlayer::durationChanged, this, [this, index](qint64 dur) {
                                      dura = static_cast<double>(dur)/60000.0;
                                      qDebug() << "duration = " << dura;
                                      filemodel->setData(index, QString().setNum(dura));
                                  });
                              

                              Now I understand what you mean but it still doesn't work

                              aha_1980A Offline
                              aha_1980A Offline
                              aha_1980
                              Lifetime Qt Champion
                              wrote on last edited by
                              #14

                              @Nemooo said in Audio duration for file manager:

                              Now I understand what you mean but it still doesn't work

                              Then please debug the code and find out where the problem is.

                              Qt has to stay free or it will die.

                              1 Reply Last reply
                              1
                              • N Nemooo

                                @jsulm said in Audio duration for file manager:

                                @Nemooo Something like (not really Qt specific):

                                auto index = filemodel->index(0, 2);
                                connect(player, &QMediaPlayer::durationChanged, this, [this, index](qint64 dur) {
                                        dura = static_cast<double>(dur)/60000.0;
                                        qDebug() << "duration = " << dura;
                                        filemodel->setData(index, QString().setNum(dura));
                                    });
                                

                                Now I understand what you mean but it still doesn't work

                                jsulmJ Offline
                                jsulmJ Offline
                                jsulm
                                Lifetime Qt Champion
                                wrote on last edited by
                                #15

                                @Nemooo I think the problem is that index changes as you're inserting new rows. You need to find a way to make sure you're using the correct index. Or you first fill in all rows into your model and then use QMediaPlayer.

                                https://forum.qt.io/topic/113070/qt-code-of-conduct

                                N 1 Reply Last reply
                                0
                                • jsulmJ jsulm

                                  @Nemooo I think the problem is that index changes as you're inserting new rows. You need to find a way to make sure you're using the correct index. Or you first fill in all rows into your model and then use QMediaPlayer.

                                  N Offline
                                  N Offline
                                  Nemooo
                                  wrote on last edited by
                                  #16

                                  @jsulm said in Audio duration for file manager:

                                  @Nemooo I think the problem is that index changes as you're inserting new rows. You need to find a way to make sure you're using the correct index. Or you first fill in all rows into your model and then use QMediaPlayer.

                                  Yes, I feel, that mistake is somewhere in wrong index but I cannot catch how.
                                  I did in a different ways. No chance.

                                  May be you know how can I get information about duration in mp3 file in different ways?

                                  jsulmJ 1 Reply Last reply
                                  0
                                  • N Nemooo

                                    @jsulm said in Audio duration for file manager:

                                    @Nemooo I think the problem is that index changes as you're inserting new rows. You need to find a way to make sure you're using the correct index. Or you first fill in all rows into your model and then use QMediaPlayer.

                                    Yes, I feel, that mistake is somewhere in wrong index but I cannot catch how.
                                    I did in a different ways. No chance.

                                    May be you know how can I get information about duration in mp3 file in different ways?

                                    jsulmJ Offline
                                    jsulmJ Offline
                                    jsulm
                                    Lifetime Qt Champion
                                    wrote on last edited by
                                    #17

                                    @Nemooo "Or you first fill in all rows into your model and then use QMediaPlayer." - what about this suggestion?

                                    https://forum.qt.io/topic/113070/qt-code-of-conduct

                                    N 1 Reply Last reply
                                    0
                                    • jsulmJ jsulm

                                      @Nemooo "Or you first fill in all rows into your model and then use QMediaPlayer." - what about this suggestion?

                                      N Offline
                                      N Offline
                                      Nemooo
                                      wrote on last edited by
                                      #18

                                      @jsulm said in Audio duration for file manager:

                                      @Nemooo "Or you first fill in all rows into your model and then use QMediaPlayer." - what about this suggestion?

                                      Tried to do this way

                                      void MainWindow::CreateTable(const QString & p) {
                                      filemodel->removeRows( 0, filemodel->rowCount() );
                                      
                                      
                                      filemodelcurrentdir = QDir(p).path();
                                      files = QDir(p).entryInfoList(QDir::Dirs | QDir::Files | QDir::NoDotAndDotDot);
                                      foreach(const QFileInfo &fi, files) {
                                          QString name = QString("%0").arg(fi.fileName());
                                      
                                      
                                      
                                          filemodel->insertRow(0);
                                          if (fi.isDir()) {
                                              filemodel->setData(filemodel->index(0, 0), name);
                                              filemodel->setData(filemodel->index(0, 0), dirIcon, Qt::DecorationRole);
                                          } else {
                                              filemodel->setData(filemodel->index(0, 0), name);
                                              filemodel->setData(filemodel->index(0, 0), fileIcon, Qt::DecorationRole);
                                      
                                          filemodel->setData(filemodel->index(0, 1), size_human(fi.size()));
                                       }
                                       }
                                      
                                      
                                          foreach(const QFileInfo &fi, files) {
                                          QString name = QString("%0").arg(fi.fileName());
                                      
                                          if (!fi.isDir()) {
                                         QMediaPlayer* player = new QMediaPlayer();
                                          player->setMedia(QUrl::fromLocalFile(filemodelcurrentdir + "/" + name));
                                      
                                                 auto index = filemodel->index(0, 2);
                                          connect(player, &QMediaPlayer::durationChanged, this, [this, index](qint64 dur) {
                                      
                                                  filemodel->setData(index, QString().setNum(static_cast<double>(dur)/60000.0));
                                              });
                                      
                                          delete player;}
                                      }
                                      
                                      
                                      filemodel->setHeaderData(0,Qt::Horizontal,QObject::tr("Name" ));
                                      filemodel->setHeaderData(1,Qt::Horizontal,QObject::tr("Size" ));
                                      filemodel->setHeaderData(2,Qt::Horizontal,QObject::tr("Duration" ));
                                      
                                      pTreeView2->setSortingEnabled(true);
                                      pTreeView2->setColumnWidth(0, 300);
                                      pTreeView2->setColumnWidth(1, 100);
                                      pTreeView2->setColumnWidth(2, 100);
                                      }
                                      

                                      The result is the same - doesn't fill the last column

                                      jsulmJ 1 Reply Last reply
                                      0
                                      • N Nemooo

                                        @jsulm said in Audio duration for file manager:

                                        @Nemooo "Or you first fill in all rows into your model and then use QMediaPlayer." - what about this suggestion?

                                        Tried to do this way

                                        void MainWindow::CreateTable(const QString & p) {
                                        filemodel->removeRows( 0, filemodel->rowCount() );
                                        
                                        
                                        filemodelcurrentdir = QDir(p).path();
                                        files = QDir(p).entryInfoList(QDir::Dirs | QDir::Files | QDir::NoDotAndDotDot);
                                        foreach(const QFileInfo &fi, files) {
                                            QString name = QString("%0").arg(fi.fileName());
                                        
                                        
                                        
                                            filemodel->insertRow(0);
                                            if (fi.isDir()) {
                                                filemodel->setData(filemodel->index(0, 0), name);
                                                filemodel->setData(filemodel->index(0, 0), dirIcon, Qt::DecorationRole);
                                            } else {
                                                filemodel->setData(filemodel->index(0, 0), name);
                                                filemodel->setData(filemodel->index(0, 0), fileIcon, Qt::DecorationRole);
                                        
                                            filemodel->setData(filemodel->index(0, 1), size_human(fi.size()));
                                         }
                                         }
                                        
                                        
                                            foreach(const QFileInfo &fi, files) {
                                            QString name = QString("%0").arg(fi.fileName());
                                        
                                            if (!fi.isDir()) {
                                           QMediaPlayer* player = new QMediaPlayer();
                                            player->setMedia(QUrl::fromLocalFile(filemodelcurrentdir + "/" + name));
                                        
                                                   auto index = filemodel->index(0, 2);
                                            connect(player, &QMediaPlayer::durationChanged, this, [this, index](qint64 dur) {
                                        
                                                    filemodel->setData(index, QString().setNum(static_cast<double>(dur)/60000.0));
                                                });
                                        
                                            delete player;}
                                        }
                                        
                                        
                                        filemodel->setHeaderData(0,Qt::Horizontal,QObject::tr("Name" ));
                                        filemodel->setHeaderData(1,Qt::Horizontal,QObject::tr("Size" ));
                                        filemodel->setHeaderData(2,Qt::Horizontal,QObject::tr("Duration" ));
                                        
                                        pTreeView2->setSortingEnabled(true);
                                        pTreeView2->setColumnWidth(0, 300);
                                        pTreeView2->setColumnWidth(1, 100);
                                        pTreeView2->setColumnWidth(2, 100);
                                        }
                                        

                                        The result is the same - doesn't fill the last column

                                        jsulmJ Offline
                                        jsulmJ Offline
                                        jsulm
                                        Lifetime Qt Champion
                                        wrote on last edited by
                                        #19

                                        @Nemooo said in Audio duration for file manager:

                                        The result is the same - doesn't fill the last column

                                        Yes, because you need to take the correct index now instead of 0.

                                        https://forum.qt.io/topic/113070/qt-code-of-conduct

                                        N 1 Reply Last reply
                                        0
                                        • jsulmJ jsulm

                                          @Nemooo said in Audio duration for file manager:

                                          The result is the same - doesn't fill the last column

                                          Yes, because you need to take the correct index now instead of 0.

                                          N Offline
                                          N Offline
                                          Nemooo
                                          wrote on last edited by
                                          #20

                                          @jsulm said in Audio duration for file manager:

                                          @Nemooo said in Audio duration for file manager:

                                          The result is the same - doesn't fill the last column

                                          Yes, because you need to take the correct index now instead of 0.

                                          May be this way?

                                            void MainWindow::CreateTable(const QString & p) {
                                            filemodel->removeRows( 0, filemodel->rowCount() );
                                          filemodelcurrentdir = QDir(p).path();
                                          files = QDir(p).entryInfoList(QDir::Dirs | QDir::Files | QDir::NoDotAndDotDot);
                                          int in = 0;
                                          foreach(const QFileInfo &fi, files) {
                                              QString name = QString("%0").arg(fi.fileName());
                                              filemodel->insertRow(in);
                                              if (fi.isDir()) {
                                                  filemodel->setData(filemodel->index(in, 0), name);
                                                  filemodel->setData(filemodel->index(in, 0), dirIcon, Qt::DecorationRole);
                                              } else {
                                                  filemodel->setData(filemodel->index(in, 0), name);
                                                  filemodel->setData(filemodel->index(in, 0), fileIcon, Qt::DecorationRole);
                                          
                                              filemodel->setData(filemodel->index(in, 1), size_human(fi.size()));
                                              }
                                             ++in;
                                             }
                                          
                                          in = 0;
                                          foreach(const QFileInfo &fi, files) {
                                              QString name = QString("%0").arg(fi.fileName());
                                              if (!fi.isDir()) {
                                             QMediaPlayer* player = new QMediaPlayer();
                                              player->setMedia(QUrl::fromLocalFile(filemodelcurrentdir + "/" + name));
                                          
                                          
                                              auto index = filemodel->index(in, 2);
                                              connect(player, &QMediaPlayer::durationChanged, this, [this, index](qint64 dur) {
                                          
                                                      filemodel->setData(index, QString().setNum(static_cast<double>(dur)/60000.0));
                                                  });
                                          
                                              delete player;}
                                              ++in;
                                          }
                                          
                                          
                                          filemodel->setHeaderData(0,Qt::Horizontal,QObject::tr("Name" ));
                                          filemodel->setHeaderData(1,Qt::Horizontal,QObject::tr("Size" ));
                                          filemodel->setHeaderData(2,Qt::Horizontal,QObject::tr("Duration" ));
                                          
                                          pTreeView2->setSortingEnabled(true);
                                          pTreeView2->setColumnWidth(0, 300);
                                          pTreeView2->setColumnWidth(1, 100);
                                          pTreeView2->setColumnWidth(2, 100);
                                           }
                                          
                                          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