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. Qt Quick search with row index issue
Forum Updated to NodeBB v4.3 + New Features

Qt Quick search with row index issue

Scheduled Pinned Locked Moved Solved QML and Qt Quick
13 Posts 2 Posters 3.0k 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.
  • V Offline
    V Offline
    Vicky Sharma
    wrote on last edited by
    #1

    Hello friends

    I am just working on Qt quick, which having table with list model, also containing search box on top of the table.
    The table contain three column "fileId", "fileName", "openFile" which filled by list model data dynamically

    When ever i searched the text i found right one but as soon play the button it send only top index of the column while its position is 9th on the table.
    I am using SortFilterProxyModel which is working perfectly for search.

    I stuck with this, suggest me how can leave it out

    TextField{
    id:searchField
    width: parent.width
    height: parent.height
    placeholderText: "Search"
    inputMethodHints: Qt.ImhNoPredictiveText

                onTextChanged: proxyModel
    
                style: TextFieldStyle {
                    background: Rectangle{
                        color: "transparent"
                    }
                }
            }
    

    SortFilterProxyModel { //calling cpp class
    id: proxyModel
    source: modelSettingData.count > 0 ? modelSettingData : null

           sortOrder: table.sortIndicatorOrder  // by default ascending order
           sortRole: modelSettingData.count > 0 ? table.getColumn(table.sortIndicatorVisible).role : ""
    
           dynamicSortFilter: true;
    
           sortCaseSensitivity: Qt.CaseInsensitive
    
           filterString: "*" + searchField.text + "*"
           filterSyntax: SortFilterProxyModel.Wildcard
           filterCaseSensitivity: Qt.CaseInsensitive
       }
    
    raven-worxR 1 Reply Last reply
    0
    • V Offline
      V Offline
      Vicky Sharma
      wrote on last edited by
      #2

      please suggest me

      1 Reply Last reply
      0
      • V Vicky Sharma

        Hello friends

        I am just working on Qt quick, which having table with list model, also containing search box on top of the table.
        The table contain three column "fileId", "fileName", "openFile" which filled by list model data dynamically

        When ever i searched the text i found right one but as soon play the button it send only top index of the column while its position is 9th on the table.
        I am using SortFilterProxyModel which is working perfectly for search.

        I stuck with this, suggest me how can leave it out

        TextField{
        id:searchField
        width: parent.width
        height: parent.height
        placeholderText: "Search"
        inputMethodHints: Qt.ImhNoPredictiveText

                    onTextChanged: proxyModel
        
                    style: TextFieldStyle {
                        background: Rectangle{
                            color: "transparent"
                        }
                    }
                }
        

        SortFilterProxyModel { //calling cpp class
        id: proxyModel
        source: modelSettingData.count > 0 ? modelSettingData : null

               sortOrder: table.sortIndicatorOrder  // by default ascending order
               sortRole: modelSettingData.count > 0 ? table.getColumn(table.sortIndicatorVisible).role : ""
        
               dynamicSortFilter: true;
        
               sortCaseSensitivity: Qt.CaseInsensitive
        
               filterString: "*" + searchField.text + "*"
               filterSyntax: SortFilterProxyModel.Wildcard
               filterCaseSensitivity: Qt.CaseInsensitive
           }
        
        raven-worxR Offline
        raven-worxR Offline
        raven-worx
        Moderators
        wrote on last edited by
        #3

        @Vicky-Sharma said:

        When ever i searched the text i found right one but as soon play the button it send only top index of the column while its position is 9th on the table.

        sry but i do not understand this sentence. Whats exactly the problem?

        --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
        If you have a question please use the forum so others can benefit from the solution in the future

        1 Reply Last reply
        0
        • V Offline
          V Offline
          Vicky Sharma
          wrote on last edited by Vicky Sharma
          #4

          Ok
          Let me explain , I have two model in qml for different -2 qml file(tabledata,searchFile) which uses the same data(coming from .cpp)
          Now when ever try to search any file by file-Name it found and show correctly.
          But when I tried to open by button (a column contain button on each row ) it's pick up the wrong file (try to open the file by indexing) because sortfilterproxymodel re-index of all display row during search i just want to stop either this re-indexing or should pick right value..

          raven-worxR 1 Reply Last reply
          0
          • V Vicky Sharma

            Ok
            Let me explain , I have two model in qml for different -2 qml file(tabledata,searchFile) which uses the same data(coming from .cpp)
            Now when ever try to search any file by file-Name it found and show correctly.
            But when I tried to open by button (a column contain button on each row ) it's pick up the wrong file (try to open the file by indexing) because sortfilterproxymodel re-index of all display row during search i just want to stop either this re-indexing or should pick right value..

            raven-worxR Offline
            raven-worxR Offline
            raven-worx
            Moderators
            wrote on last edited by
            #5

            @Vicky-Sharma
            i see.
            You need to map the index to the source model before using it.

            --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
            If you have a question please use the forum so others can benefit from the solution in the future

            1 Reply Last reply
            0
            • V Offline
              V Offline
              Vicky Sharma
              wrote on last edited by Vicky Sharma
              #6

              Yes I did in qml

              SortFilterProxyModel { //calling cpp class
              id: proxyModel
              //this provide source to sortfilterproxymodel classs
              source: modelSettingData11.count > 0 ? modelSettingData11 : null

                     sortCaseSensitivity: Qt.CaseInsensitive
                     filterString: "*" + searchField.text + "*"
                     filterSyntax: SortFilterProxyModel.Wildcard
                     filterCaseSensitivity: Qt.CaseInsensitive
                 }
              

              Is it need to clear or reset on every text to search ?

              except this if another method to call or mapToSource than please post here

              raven-worxR 1 Reply Last reply
              0
              • V Vicky Sharma

                Yes I did in qml

                SortFilterProxyModel { //calling cpp class
                id: proxyModel
                //this provide source to sortfilterproxymodel classs
                source: modelSettingData11.count > 0 ? modelSettingData11 : null

                       sortCaseSensitivity: Qt.CaseInsensitive
                       filterString: "*" + searchField.text + "*"
                       filterSyntax: SortFilterProxyModel.Wildcard
                       filterCaseSensitivity: Qt.CaseInsensitive
                   }
                

                Is it need to clear or reset on every text to search ?

                except this if another method to call or mapToSource than please post here

                raven-worxR Offline
                raven-worxR Offline
                raven-worx
                Moderators
                wrote on last edited by
                #7

                @Vicky-Sharma said:

                Yes I did in qml

                1. i don't see any mapToSource call
                2. this method is not invokable per definition so actually it isn't even callable

                --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
                If you have a question please use the forum so others can benefit from the solution in the future

                1 Reply Last reply
                0
                • V Offline
                  V Offline
                  Vicky Sharma
                  wrote on last edited by
                  #8

                  ok
                  But it does filter by name

                  anyway let me do as per your suggestion.

                  raven-worxR 1 Reply Last reply
                  0
                  • V Vicky Sharma

                    ok
                    But it does filter by name

                    anyway let me do as per your suggestion.

                    raven-worxR Offline
                    raven-worxR Offline
                    raven-worx
                    Moderators
                    wrote on last edited by
                    #9

                    @Vicky-Sharma
                    yes, filtering is one thing.
                    But using the index after the proxy model already did the filtering requires mapping (to get the row you expect for example).

                    You haven't posted the code where are you connect the button and the corresponding model index is used.

                    --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
                    If you have a question please use the forum so others can benefit from the solution in the future

                    1 Reply Last reply
                    0
                    • V Offline
                      V Offline
                      Vicky Sharma
                      wrote on last edited by
                      #10

                      TableViewColumn{
                      id:likeBtnColumn;
                      role: "playBtn";
                      resizable: false;
                      movable: false;
                      title: "Likes ";
                      width: table.width/5.95

                             delegate: Component {
                      
                              Button{
                                 id:playBtn;
                                 width: likeBtnColumn.width/3;
                      
                                 Image {
                                 id: image
                                source:/qrc/icons/playbtn.png
                                 width: playBtn.width/2
                                 height: playBtn.height-2          
                                 }
                                 onClicked:{
                                     var likeBtnPressed = modelSettingData.get(styleData.row).fileId;
                      

                      //By this line i received fileId which is not generating right value during search //but without click on search button it provides right value
                      console.log("you pressed : " + likeBtnPressed);
                      //This line debug current row of the table which is right
                      console.log("you pressed22 : " + table.currentRow);
                      mainWindowCalling.slotSongsLikes(likeBtnPressed);
                      }
                      }
                      }
                      }

                      raven-worxR 1 Reply Last reply
                      0
                      • V Vicky Sharma

                        TableViewColumn{
                        id:likeBtnColumn;
                        role: "playBtn";
                        resizable: false;
                        movable: false;
                        title: "Likes ";
                        width: table.width/5.95

                               delegate: Component {
                        
                                Button{
                                   id:playBtn;
                                   width: likeBtnColumn.width/3;
                        
                                   Image {
                                   id: image
                                  source:/qrc/icons/playbtn.png
                                   width: playBtn.width/2
                                   height: playBtn.height-2          
                                   }
                                   onClicked:{
                                       var likeBtnPressed = modelSettingData.get(styleData.row).fileId;
                        

                        //By this line i received fileId which is not generating right value during search //but without click on search button it provides right value
                        console.log("you pressed : " + likeBtnPressed);
                        //This line debug current row of the table which is right
                        console.log("you pressed22 : " + table.currentRow);
                        mainWindowCalling.slotSongsLikes(likeBtnPressed);
                        }
                        }
                        }
                        }

                        raven-worxR Offline
                        raven-worxR Offline
                        raven-worx
                        Moderators
                        wrote on last edited by
                        #11

                        @Vicky-Sharma
                        k i see whats the problem is.
                        Either you save the source row along with the button and use this stored row.
                        Or another little cleaner approach would be to introduce another item data role in your source model. And for that new custom item data role you simply return the row.
                        This has the side-effect that the proxymodel internally maps the row correctly to retrieve the data role form the correct source index.

                        --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
                        If you have a question please use the forum so others can benefit from the solution in the future

                        1 Reply Last reply
                        0
                        • V Offline
                          V Offline
                          Vicky Sharma
                          wrote on last edited by
                          #12

                          @raven-worx

                          I tried your idea and found that during search table data invisible not clear that'swhy when ever search it's re-index but still having same id as past and provide previous id.

                          I tried to clear model and re-create on every search's text but still same problem and one more thing with this code no need to use "mapToSource" it did automatically whenever select from Sql db and send to Qml.

                          Now suggest me how can do ?

                          1 Reply Last reply
                          0
                          • V Offline
                            V Offline
                            Vicky Sharma
                            wrote on last edited by
                            #13

                            Thanks @raven-worx

                            I had solve the issue by providing same "role" to the open file now it's accessing right value by use of "styleData.value" on click button

                            Thanks again sir

                            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