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. [Solved] Read File name from folderlistmodel
Forum Updated to NodeBB v4.3 + New Features

[Solved] Read File name from folderlistmodel

Scheduled Pinned Locked Moved QML and Qt Quick
10 Posts 3 Posters 3.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.
  • B Offline
    B Offline
    beemaneni
    wrote on last edited by
    #1

    In List View i have stored n number of files.How to read File name from folderlistmodel based on index..Here i know the value of index.up on clicking on listview i need to find out respective filename based on index. i found get method in folderListModel but of no use...Can any one help me out where i am going wrong r is there really a way to finout filename
    @FolderListModel{
    id: folderList
    folder: imagePath
    nameFilters: ["*.png"]
    }
    MouseArea {
    anchors.fill: parent
    property var valuex
    onClicked: {
    xxx.text = folderList.get(index,"fileName")
    }
    @

    Thanks in Advance

    Bala B
    Infinite Computer systems
    Chennai

    1 Reply Last reply
    0
    • dheerendraD Offline
      dheerendraD Offline
      dheerendra
      Qt Champions 2022
      wrote on last edited by
      #2

      Try this.
      @
      ListView {
      id : view
      ....
      ....
      ....

      MouseArea {
      anchors.fill: parent
      onClicked: {
      console.log(" I am here"+currentIndex)
      console.log(" My name is ="+view.model.get(currentIndex,"fileName"))
      }
      }
      }
      @

      Dheerendra
      @Community Service
      Certified Qt Specialist
      http://www.pthinks.com

      1 Reply Last reply
      0
      • B Offline
        B Offline
        beemaneni
        wrote on last edited by
        #3

        Hi Dheerendra..
        Thanks for reply..
        That doesnt work...

        Bala B
        Infinite Computer systems
        Chennai

        1 Reply Last reply
        0
        • dheerendraD Offline
          dheerendraD Offline
          dheerendra
          Qt Champions 2022
          wrote on last edited by
          #4

          ListView has property called currentIndex. It works based on that. Here is complete example I tried on 3 platforms.

          @ListView {
          id : view
          width: 200; height: 400

          FolderListModel {
              id: folderModel
              nameFilters: ["*.qml"]
          }
          
          Component {
              id: fileDelegate
              Text { text: fileName }
          }
          
          model: folderModel
          delegate: fileDelegate
              MouseArea {
                  anchors.fill: parent
                  onClicked: {
                      console.log(" I am here"+currentIndex)
                      console.log(" I am ok ="+view.model.get(currentIndex,"fileName"))
                  }
              }
          

          }
          @

          Dheerendra
          @Community Service
          Certified Qt Specialist
          http://www.pthinks.com

          1 Reply Last reply
          0
          • B Offline
            B Offline
            beemaneni
            wrote on last edited by
            #5

            Hi
            Thanks dheerendra..It works fine...but it does not work with currentIndex..It works with index.

            And i found one more working.Here is the code..
            @ MouseArea {
            anchors.fill: parent
            onClicked: {
            xxx.text = folderList.folder + fileName
            }
            }@

            Thanks
            Bala Beemaneni

            Bala B
            Infinite Computer systems
            Chennai

            1 Reply Last reply
            0
            • dheerendraD Offline
              dheerendraD Offline
              dheerendra
              Qt Champions 2022
              wrote on last edited by
              #6

              Good that it solved your issue. As side note, 'index' is visible inside the delegate. 'CurrentIndex' is inside the ListView. Since your mouseArea is inside the delegate, you need to use 'index' only. If your mouseArea is inside the View, you need to use 'currentIndex'.

              Dheerendra
              @Community Service
              Certified Qt Specialist
              http://www.pthinks.com

              1 Reply Last reply
              0
              • B Offline
                B Offline
                beemaneni
                wrote on last edited by
                #7

                Thanks Dheerendra..Thanks for ur help :-)

                Reagrds
                Bala Beemaneni

                Bala B
                Infinite Computer systems
                Chennai

                1 Reply Last reply
                0
                • T Offline
                  T Offline
                  Traxx
                  wrote on last edited by
                  #8

                  Why do i get error "TypeError: Result of expression 'songView.model.get' [undefined] is not a function" when i use

                  @view.model.get(index,"fileName")@

                  Beemaneni.Can you please advice how you get the file name using code below.I get the file name but it also include the whole path leading to the files and the filename change when i just scrolling listview without selecting it.

                  @xxx.text = folderList.folder + fileName@

                  1 Reply Last reply
                  0
                  • B Offline
                    B Offline
                    beemaneni
                    wrote on last edited by
                    #9

                    try with this
                    @ view.model.get(currentIndex,"fileName")@

                    If u dont mind post ur code ,let me have a look at that

                    Thanks
                    Bala Beemaneni

                    Bala B
                    Infinite Computer systems
                    Chennai

                    1 Reply Last reply
                    0
                    • T Offline
                      T Offline
                      Traxx
                      wrote on last edited by
                      #10

                      Here the simplified code.Anyway i manage to solve.Kind of dirty but at least it work.The code is below.Just make sure only call it when necessary else when scrolling lisview, the file name keep changing even when just scrolling without selecting it.Takes me almost a week to figure it out.Thanks.

                      //WORKING CODE
                      @
                      View.currentItem.DataModel.fileName
                      @

                      //SAMPLE CODE
                      @
                      ListView {
                      id: View
                      clip: true
                      model: ListModelling
                      delegate: listcomponent
                      }
                      FolderListModel {
                      id: ListModelling
                      folder: "file:/accounts/1000/shared"
                      //folder: "file"
                      showDirs: true
                      }
                      ListModel {
                      id: ListModel
                      ListElement {
                      folder: ""
                      index: 0
                      }
                      }

                       Component {
                         id: listcomponent
                         ListItem {
                             id: listitem
                             property variant DataModel: model
                             Text { 
                                id: showname
                                 text: fileName
                                 anchors.verticalCenter: parent.verticalCenter
                                 anchors.left: foldersymbol.right
                                 anchors.leftMargin: 10
                                 anchors.right: parent.right
                               }
                           }
                       }
                      

                      @

                      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