Qt Quick search with row index issue



  • 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
       }


  • please suggest me


  • Moderators

    @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?



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


  • Moderators

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



  • 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


  • Moderators

    @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


  • ok
    But it does filter by name

    anyway let me do as per your suggestion.


  • Moderators

    @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.



  • 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);
    }
    }
    }
    }


  • Moderators

    @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.



  • @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 ?



  • 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


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.