title: Photo gallery in iOS and Android
body: <p>I am developing an app for mobile to run in <code>iOS</code> and <code>Android</code> and I am facing some difficulties to access the <code>image gallery</code> of the devices with <code>Qml</code>.</p>
  
  <p>I need to list the images from image gallery in a <code>GridView</code>.</p>
  
  <p>I have tried to return the pictures folder using <code>QStandardPaths</code> but it just works for desktop computers. For smartphones running <code>iOS</code> and <code>Android</code> it returns a folder that is not the folder of the gallery.</p>
  
  <p>Could someone help me to figure out how I can do that? My code is below:</p>
  
  <p>main.cpp</p>
  
  <pre><code>#include &lt;QGuiApplication&gt;
  #include &lt;QQmlApplicationEngine&gt;
  
  #include &lt;QtQml&gt;
  
  #include "caminhoimagens.h"
  
  int main(int argc, char *argv[])
  {
      QGuiApplication app(argc, argv);
  
      qmlRegisterType&lt;caminhoImagens&gt;("PathImagens", 1, 0, "CaminhoImagens");
  
      QQmlApplicationEngine engine;
      engine.load(QUrl(QStringLiteral("qrc:/main.qml")));
  
      return app.exec();
  }
  </code></pre>
  
  <p>main.qml</p>
  
  <pre><code>import QtQuick 2.4
  import QtQuick.Window 2.2
  import QtQuick.Controls 1.3
  import QtQuick.Dialogs 1.2
  
  import Qt.labs.folderlistmodel 2.1
  
  import PathImagens 1.0
  
  Window {
      visible: true
  
      width: 360
      height: 640
  
      maximumHeight: 640
      minimumHeight: 640
  
      maximumWidth: 360
      minimumWidth: 360
  
      title: "Acessar Galeria Test"
  
      Rectangle {
          id: principal
  
          anchors.fill: parent
  
          ListModel {
              id: listModel
          }
  
          FolderListModel {
              id: folderListModel
  
              folder: "file://" + caminhoImagens.retornaCaminhoImagens()
              nameFilters: "*.jpeg"
          }
  
          CaminhoImagens {
              id: caminhoImagens
          }
  
          Item {
              id: listaFotosDelegate
  
              property Component delegateComponent: listaFotosDelegateComponent
  
              Component {
                  id: listaFotosDelegateComponent
  
                  Image {
                      id: imagem
  
                      source: folderListModel.folder + "/" + fileName
  
                      width: principal.width / 4.2
                      height: principal.width / 4.2
  
                      fillMode: Image.PreserveAspectCrop
                  }
              }
          }
  
          GridView {
              id: listaFotosGridView
  
              anchors.fill: parent
  
              clip: true
  
              model: folderListModel
  
              delegate: listaFotosDelegate.delegateComponent
  
              cellWidth: parent.width / 4
              cellHeight: parent.width / 4
          }
      }
  }
  </code></pre>
  
  <p>caminhoimagens.h</p>
  
  <pre><code>#ifndef CAMINHOIMAGENS_H
  #define CAMINHOIMAGENS_H
  
  #include &lt;QObject&gt;
  #include &lt;QStandardPaths&gt;
  
  class caminhoImagens : public QObject
  {
      Q_OBJECT
  
  public slots:
      QString retornaCaminhoImagens();
  
  public:
      caminhoImagens();
  };
  
  #endif // CAMINHOIMAGENS_H
  </code></pre>
  
  <p>caminhoimagens.cpp</p>
  
  <pre><code>#include "caminhoimagens.h"
  
  caminhoImagens::caminhoImagens()
  {
  
  }
  
  QString caminhoImagens::retornaCaminhoImagens()
  {
      return QStandardPaths::locate(QStandardPaths::PicturesLocation, QString(), QStandardPaths::LocateDirectory);
  }
  </code></pre>