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] QML Fetch value from current row in a tableview.

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

Scheduled Pinned Locked Moved QML and Qt Quick
5 Posts 2 Posters 3.3k 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.
  • S Offline
    S Offline
    skammers
    wrote on last edited by
    #1

    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;
    }
    @

    1 Reply Last reply
    0
    • p3c0P Offline
      p3c0P Offline
      p3c0
      Moderators
      wrote on last edited by
      #2

      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

      157

      1 Reply Last reply
      0
      • S Offline
        S Offline
        skammers
        wrote on last edited by
        #3

        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.

        ?

        1 Reply Last reply
        0
        • p3c0P Offline
          p3c0P Offline
          p3c0
          Moderators
          wrote on last edited by
          #4

          What is masterResource and filteredList ?

          157

          1 Reply Last reply
          0
          • S Offline
            S Offline
            skammers
            wrote on last edited by
            #5

            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 :)

            1 Reply Last reply
            1

            • Login

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • Users
            • Groups
            • Search
            • Get Qt Extensions
            • Unsolved