title: How can I make the thumbnails of video files or pictures for the icons of gridview?
body: <p>I am developing an android app using QML and want to demonstrate a gridview of a collection of video files in it. I want to show icons as thumbnails of those video files as shown in below. I don't know whether I should use QFileIconProvider or any others. I have no idea. Please help.</p>
  
  <p><a href="https://i.stack.imgur.com/HXcnB.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/HXcnB.jpg" alt="enter image description here"></a> </p>
  
  <p><strong>main.qml</strong></p>
  
  <pre><code>...
       GridView {
                 anchors.fill: parent
                 cellWidth: 100; cellHeight: 100
                 focus: true
  
                 model: FileModel{
                     id: myModel
                     folder: "/mnt/sdcard/app_pictureFrameImage"
                     nameFilters: ["*.mp4","*.jpg"]
                 }
  
                 currentIndex: 0
  
                 highlight: Rectangle { width: 80; height: 80; color: "lightsteelblue" }
  
                 delegate: Item {
                     width: 100; height: 100
  
                     Image {
                         id: myIcon
                         y: 20; anchors.horizontalCenter: parent.horizontalCenter
                         source: icon
                     }
                     Text {
                         anchors { top: myIcon.bottom; horizontalCenter: parent.horizontalCenter }
                         text: fileName
                     }
                     MouseArea {
                         anchors.fill: parent
                         onClicked: parent.GridView.view.currentIndex = index
                     }
                 }
             }
  ...
  </code></pre>
  
  <p>The following code extracts all the video or pictures found in the system. With the help of the following code, how can I make the thumbnails of video files or pictures for the icons of gridview? </p>
  
  <p><strong>filemodel.h</strong></p>
  
  <pre><code>#ifndef FILEMODEL_H
  #define FILEMODEL_H
  
  #include &lt;QAbstractListModel&gt;
  #include &lt;QDirIterator&gt;
  #include &lt;QUrl&gt;
  #include &lt;QMetaType&gt;
  #include &lt;QFuture&gt;
  #include &lt;QtConcurrent/QtConcurrent&gt;
  #include &lt;iostream&gt;
  using namespace std;
  
  struct File
  {
      Q_GADGET
      Q_PROPERTY(QString name MEMBER name)
      Q_PROPERTY(QUrl url MEMBER url)
  public:
      QString name;
      QUrl url;
      File(const QString&amp; name=""){            
          this-&gt;name = QFileInfo(name).fileName();
          this-&gt;url = QUrl::fromLocalFile(name);
      }
  };
  Q_DECLARE_METATYPE(File)
  
  class FileModel : public QAbstractListModel
  {
      enum dashBoardRoles {
          NameRole=Qt::UserRole+1,
          URLRole
      };
      Q_OBJECT
      Q_PROPERTY(QString folder READ folder WRITE setFolder NOTIFY folderChanged)
      Q_PROPERTY(QStringList nameFilters READ nameFilters WRITE setNameFilters NOTIFY nameFiltersChanged)
  public:
      FileModel(QObject *parent=Q_NULLPTR):QAbstractListModel(parent){
      }
  
      Q_INVOKABLE QVariant get(int index){
          return QVariant::fromValue(m_all_dirs[index]);
      }
  
      int rowCount(const QModelIndex &amp;parent=QModelIndex()) const{
          Q_UNUSED(parent)
          return m_all_dirs.count();
      }
      QVariant data(const QModelIndex &amp;index, int role = Qt::DisplayRole) const{
          if(index.row()&lt;0 &amp;&amp; index.row()&gt;= rowCount())
              return QVariant();
          File  file = m_all_dirs[index.row()];
          if(role == NameRole)
              return file.name;
          else if(role == URLRole)
              return file.url;
          return QVariant();
      }
  
      QHash&lt;int, QByteArray&gt; roleNames() const {
          QHash &lt;int,QByteArray&gt; roles;
          roles [NameRole]="fileName";
          roles [URLRole]="url";
          return roles;
      }
  
      QString folder() const{
          return mFolder;
      }
  
      void setFolder(const QString &amp;folder)
      {
          if(mFolder == folder)
              return;
          mFolder = folder;
          emit folderChanged();
          findFiles();
      }
  
      QStringList nameFilters() const{
          return mNameFilters;
      }
  
      void setNameFilters(const QStringList &amp;nameFilters){
          if(mNameFilters == nameFilters)
              return;
          mNameFilters = nameFilters;
          emit nameFiltersChanged();
          findFiles();
      }
  
  signals:
      void folderChanged();
      void nameFiltersChanged();
  
  private:
      void findFiles(){
  
          beginResetModel();
          m_all_dirs.clear();
          if(QDir(mFolder).exists()){
              QFuture&lt;QStringList&gt; future = QtConcurrent::run([=]() {
                  QStringList files;
                  QDirIterator it(mFolder, mNameFilters, QDir::Files, QDirIterator::Subdirectories);
                  while (it.hasNext()){
                      files&lt;&lt;it.next();
                  }
                  return files;
              });
              QStringList fullNames = future.result();
              for(const QString&amp; fullName: fullNames){
                  File file{fullName};
                  m_all_dirs &lt;&lt; file;
              }
          }
          endResetModel();
      }
      QString mFolder;
      QList&lt;File&gt; m_all_dirs;
      QStringList mNameFilters;
  };
  
  #endif // FILEMODEL_H
  </code></pre>