I'm developing an app for iOS
and Android
and I'm having some difficulty accessing galeria de images
of devices with QML.
I need to list the image gallery images in a GridView
I've been trying to use QStandardPaths
but it only works for dektop computers. For smartphones running iOS
and Android
the returned folder is different from the images gallery folder ..
Does anyone know how to access this? My code is below:
main.cpp
#include <QGuiApplication>
#include <QQmlApplicationEngine>
#include <QtQml>
#include "caminhoimagens.h"
int main(int argc, char *argv[])
{
QGuiApplication app(argc, argv);
qmlRegisterType<caminhoImagens>("PathImagens", 1, 0, "CaminhoImagens");
QQmlApplicationEngine engine;
engine.load(QUrl(QStringLiteral("qrc:/main.qml")));
return app.exec();
}
main.qml
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
}
}
}
pathimages.h
#ifndef CAMINHOIMAGENS_H
#define CAMINHOIMAGENS_H
#include <QObject>
#include <QStandardPaths>
class caminhoImagens : public QObject
{
Q_OBJECT
public slots:
QString retornaCaminhoImagens();
public:
caminhoImagens();
};
#endif // CAMINHOIMAGENS_H
pathimagens.cpp
#include "caminhoimagens.h"
caminhoImagens::caminhoImagens()
{
}
QString caminhoImagens::retornaCaminhoImagens()
{
return QStandardPaths::locate(QStandardPaths::PicturesLocation, QString(), QStandardPaths::LocateDirectory);
}