Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Mobile and Embedded
  4. How to use QGalleryQueryModel with QML?
Forum Updated to NodeBB v4.3 + New Features

How to use QGalleryQueryModel with QML?

Scheduled Pinned Locked Moved Mobile and Embedded
13 Posts 6 Posters 6.4k 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.
  • M Offline
    M Offline
    mismail
    wrote on last edited by
    #1

    Hi everyBody,

    I am trying to use QGalleryQueryModel and QML to display the images on the device within my application.
    but without any results here what I did
    //GalleryModel.cpp
    @ GalleryModel::GalleryModel(QObject *parent) :
    QGalleryQueryModel(parent)
    {
    QHash<int, QByteArray> properties;
    properties.insert(Qt::UserRole + 1, "url");
    setRoleNames(properties);
    }

    QVariant GalleryModel::data(const QModelIndex &index, int role) const
    {
    return role == (Qt::UserRole + 1) && index.isValid()
    ? itemUrl(index).path()
    : QGalleryQueryModel::data(index, role);
    }@
    

    GalleryModel.h
    @ #ifndef GALLERYMODEL_H
    #define GALLERYMODEL_H

    #include <QGalleryQueryModel>
     
    QTM_USE_NAMESPACE
     
    class GalleryModel : public QGalleryQueryModel
    {
    Q_OBJECT
    public:
    explicit GalleryModel(QObject *parent = 0);
    QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const;
    signals:
     
    public slots:
     
    };
     
    #endif // GALLERYMODEL_H@
    

    //main.cpp
    @ #include <QtGui/QApplication>
    #include "qmlapplicationviewer.h"
    #include <QDeclarativeContext>
    #include <QGalleryQueryModel>
    #include <QDocumentGallery>
    #include <QHash>
    #include "gallerymodel.h"

    QTM_USE_NAMESPACE
     
    int main(int argc, char *argv[])
    {
    QApplication app(argc, argv);
     
    QmlApplicationViewer viewer;
    viewer.setOrientation(QmlApplicationViewer::ScreenOrientationAuto);
     
    QDocumentGallery * gallery = new QDocumentGallery;
    GalleryModel * model = new GalleryModel(gallery);
    model->setRootType(QDocumentGallery::Image);
     
     
    viewer.rootContext()->setContextProperty("galleryModel", model);
    viewer.setMainQmlFile&#40;QLatin1String("qml/GalleryProject/main.qml"&#41;);
    viewer.showExpanded();
     
    return app.exec();
    }
    

    @
    //main.qml
    @ import Qt 4.7
    import QtQuick 1.0
    import QtMobility.gallery 1.1

    Rectangle {
    width: 1024
    height: 768
     
    GridView {
    anchors.fill: parent
    cellWidth: 128
    cellHeight: 128
     
    model: galleryModel
     
    delegate: Image {
    source: url
    width: 128
    height: 128
     
    }
    }
    }
    

    @
    but nothing displayed
    I will appreciate any Help Thank you

    1 Reply Last reply
    0
    • J Offline
      J Offline
      jbarron
      wrote on last edited by
      #2

      Why are you instantiating the model on the C++ side? There is a QML model you should be able to use for this:

      http://doc.qt.nokia.com/qtmobility-1.2/qml-documentgallerymodel.html

      I notice that you insert a new property called "url", but there is already a property called "url" in the Gallery model so perhaps that is causing some problems. If you remove that additional code and simply call the base class implementation, does it work then?

      1 Reply Last reply
      0
      • M Offline
        M Offline
        mismail
        wrote on last edited by
        #3

        When I use the QML model the application takes a lot of memory and could not load all the images it loads only two of them , I think this is because the images size which is (1.5 MB). and I got the following errors
        bq. [Qt Message] qrc:/qml/contactface/delegates/GalleryDelegate.qml:18:17: QML Image: Error decoding: file:///e:/images/datanil/31/image.jpg: Unable to read image data
        [Qt Message] QVGImagePool: cannot reclaim sufficient space for a 2592x1944 image

        When I used QGalleryQueryModel I am still not able to display the images
        @QGalleryQueryModel * model = new QGalleryQueryModel;
        model->setRootType(QDocumentGallery::Image);

        viewer.rootContext()->setContextProperty("galleryModel", model);
        viewer.setSource(QUrl(QLatin1String("qrc:/qml/GalleryProject/main.qml")));@
        

        and the QML file was
        @GridView {
        anchors.fill: parent
        cellWidth: 128
        cellHeight: 128

             model:galleryModel
        
             delegate: Image {
                 source: url
                 width: 128
                 height: 128
                 onSourceChanged: {
                     console.log("source changed");
                 }
        
             }
         }@
        

        Thank you

        1 Reply Last reply
        0
        • M Offline
          M Offline
          mismail
          wrote on last edited by
          #4

          I think that there is a bug in the QGalleryQueryModel

          1 Reply Last reply
          0
          • M Offline
            M Offline
            mismail
            wrote on last edited by
            #5

            Is there anybody here?

            1 Reply Last reply
            0
            • EddyE Offline
              EddyE Offline
              Eddy
              wrote on last edited by
              #6

              bq.
              [Qt Message] QVGImagePool: cannot reclaim sufficient space for a 2592×1944 image

              I would try with a much smaller image first if i were you. I think your image is rather big for a mobile application.

              Qt Certified Specialist
              www.edalsolutions.be

              1 Reply Last reply
              0
              • M Offline
                M Offline
                mismail
                wrote on last edited by
                #7

                but those image are displayed using the mobile gallery, also I tried small images and it was working.
                I have another question does the gallery searches all photos in the mobile or it searches on specific places?

                1 Reply Last reply
                0
                • J Offline
                  J Offline
                  Jano
                  wrote on last edited by
                  #8

                  Hi,

                  I have same code as above. But same results. I m not retreiving any images.

                  NOTE: im using QtMobility 1.1

                  I can't use http://doc.qt.nokia.com/qtmobility-1.2/qml-documentgallerymodel.html since filters does not work properly:

                  http://bugreports.qt.nokia.com/browse/QTMOBILITY-1741

                  So im wondering what is wrong with above code and why images are not retreived?

                  1 Reply Last reply
                  0
                  • M Offline
                    M Offline
                    mismail
                    wrote on last edited by
                    #9

                    Hi Jano,
                    Finally I am able to use QGalleryQueryModel it took me several weeks to make it work.
                    and here are the solution
                    @ThumbnailModel::ThumbnailModel(QAbstractGallery *gallery, QObject *parent)
                    : QGalleryQueryModel(gallery, parent)
                    {
                    setRootType(QDocumentGallery::Image);

                    QHash<int, QByteArray> properties;
                    properties.insert(Qt::UserRole + 1, "url");
                    setRoleNames(properties);
                    
                    QHash<int, QString> columns;
                    properties.insert(Qt::UserRole + 1, "url");
                    addColumn(columns);
                    execute();
                    

                    }@

                    I hope I helped you

                    1 Reply Last reply
                    0
                    • J Offline
                      J Offline
                      Jano
                      wrote on last edited by
                      #10

                      Hi Mismael

                      It is neccessary to pass QAbstractGallery into constructor?

                      Can you share all code or even project?

                      Many Thanks for your help!

                      1 Reply Last reply
                      0
                      • J Offline
                        J Offline
                        Jano
                        wrote on last edited by
                        #11

                        Please,

                        If is possible just post whole .h and .cpp files and main.cpp ( or where do you use tuhmbnailmodel ).

                        It will be really helpfull.

                        Many thanks

                        1 Reply Last reply
                        0
                        • I Offline
                          I Offline
                          itwiz
                          wrote on last edited by
                          #12

                          In QML can you try this
                          @ delegate: Image {
                          source: url
                          width: 128
                          height: 128
                          //add these two lines
                          sourceSize.width: 1024
                          sourceSize.height:1024
                          onSourceChanged: {
                          console.log("source changed");
                          }@
                          This will fix " [Qt Message] QVGImagePool: cannot reclaim sufficient space for a 2592×1944 image" issue

                          1 Reply Last reply
                          0
                          • C Offline
                            C Offline
                            codenode
                            wrote on last edited by
                            #13

                            Any update on this?
                            The standard QML Gallery Model still lets the app hang for minutes...

                            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