[Solved] QML Fetch value from current row in a tableview.



  • Hey all!

    So I Have a tableview containing text. Under it I have a textfield which I want to display the text corresponding to the current selected row in the tableview. My tableview is based on a model which I get from C++. So when you click on a row in the tableview I want the text field to update as well. How can I do this?

    I've tried several options similar to the one underneath here, but cant get it to work.

    @
    function rowChanged(){
    langInput.text = masterTable.model.get(styleData.value).english;
    }
    @


  • Moderators

    Hi,

    "get":http://qt-project.org/doc/qt-5/qml-qtqml-models-listmodel.html#get-method requires an integer. Also try using directly the model.
    For eg.
    @
    Text {
    text: masterResource.get(1).title
    }
    @

    //masterResource is model



  • Thanks for reply!

    My tableview is based on a list from C++. So the model is masterResource.filteredList.

    I tried this:

    @
    langInput.text = masterResource.filteredList.get(1).english;
    @

    but then I got this:
    qrc:///main.qml:981: TypeError: Property 'get' of object [object Object] is not a function.

    ?


  • Moderators

    What is masterResource and filteredList ?



  • The filteredList is a list of objects. And masterResource is the connection to the C++ world.

    But I got it to work using this:

    @
    langInput.text = masterResource.filteredList[masterTable.currentRow].english;
    @

    Thanks :)


Log in to reply
 

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