Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. Get an element from FolderListModel

Get an element from FolderListModel

Scheduled Pinned Locked Moved QML and Qt Quick
4 Posts 2 Posters 3.1k 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.
  • L Offline
    L Offline
    luca
    wrote on last edited by
    #1

    Hi all,
    I need to get a filename from a FolderListModel as in the following example:

    @
    ...
    ...
    Rectangle {
    width: 360
    height: 360

    MouseArea {
        anchors.fill: parent
        onClicked: {
            Qt.quit();
        }
        Image {
            id: immagine
            source: lista_immagini_model.get(0)
    
        }
    }
    
    FolderListModel {
        id: lista_immagini_model
        folder: "../../Immagini/"
        nameFilters: ["*.jpg"]
    }
    

    }
    ...
    ...
    @

    But :
    @
    lista_immagini_model.get(0)
    @
    doesn't exists...

    Is there a way to do that?

    1 Reply Last reply
    0
    • L Offline
      L Offline
      luca
      wrote on last edited by
      #2

      With a ListModel it works:
      @
      ...
      ...
      Image {
      id: immagine
      source: lista_immagini_model.get(0).fileName

          }
      

      ...
      ...
      ListModel {
      id: lista_immagini_model

          ListElement {
              fileName: "../../Immagini/DSC_0355_art.JPG"
          }
          ListElement {
              fileName: "../../Immagini/DSC_0366.JPG"
          }
          ListElement {
              fileName: "../../Immagini/IMG_0244.JPG"
          }
      }
      

      @

      How can I load the content of a FolderListModel in a ListModel?

      1 Reply Last reply
      0
      • L Offline
        L Offline
        luca
        wrote on last edited by
        #3

        Ok, suppose I want to create a model in C++ (Ex. QStringListModel) with the filenames I need.
        What should be the better way to access that model from QML?

        1 Reply Last reply
        0
        • T Offline
          T Offline
          task_struct
          wrote on last edited by
          #4

          Hello,

          ListModel has method called get(), but FolderListModel doesn't.

          I think the easiest way will be to extend current implementation of FolderListModel.

          You can see the source code "here":http://developer.qt.nokia.com/doc/qt-4.8/src-imports-folderlistmodel.html

          See the implementation of isFolder function and add another one that returns filename by given index.

          "Most good programmers do programming not because they expect to get paid or get adulation by the public, but because it is fun to program."

          • Linu...
          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