Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. QML and QAbstractTableModel
Forum Updated to NodeBB v4.3 + New Features

QML and QAbstractTableModel

Scheduled Pinned Locked Moved Solved General and Desktop
5 Posts 2 Posters 1.5k Views 2 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.
  • O Offline
    O Offline
    olejl77
    wrote on last edited by
    #1

    I have a subclassed a QAbstractTableModel, and I want to show the data in QML in various ways. Please see a small example here: https://github.com/olejl77/demomodel

    It seems to be working, but change in values are not reflected in the QML. Also how can I show a single value from the model in QML?

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

      @olejl77 I see that you update the values in Row objects but these changes needs to be notified to the view. This can be done using dataChanged signal. So once a Rows value is updated you can for eg. emit a signal from that Row object and this signal can be connected to a slot in the model. Later this slot will emit dataChanged signal. This signal takes an index which you can create using exact row and column which is going to be updated. You can store the row number in Row object itself whereas column can be hardcoded since they are only 2.

      Also how can I show a single value from the model in QML?

      Create a Q_INVOKABLE function or a public slot inside the model which will return the single value from there.

      157

      1 Reply Last reply
      2
      • O Offline
        O Offline
        olejl77
        wrote on last edited by
        #3

        @p3c0: Thanks for the information. That solved the issue with the ListView and GridView not updating.
        I also managed to retrieve a single value, however I didn't manage to "bind" that value in order for it to update when it changes. How can I do that?
        (I have updated github)

        p3c0P 1 Reply Last reply
        0
        • O olejl77

          @p3c0: Thanks for the information. That solved the issue with the ListView and GridView not updating.
          I also managed to retrieve a single value, however I didn't manage to "bind" that value in order for it to update when it changes. How can I do that?
          (I have updated github)

          p3c0P Offline
          p3c0P Offline
          p3c0
          Moderators
          wrote on last edited by
          #4

          @olejl77

          I also managed to retrieve a single value, however I didn't manage to "bind" that value in order for it to update when it changes. How can I do that?

          Try this:
          https://wiki.qt.io/How_to_Bind_a_QML_Property_to_a_C%2B%2B_Function

          After that when the value in your model changes just call someFunction(your function) which will then emit a signal which will notify the QML and update the text.

          157

          1 Reply Last reply
          2
          • O Offline
            O Offline
            olejl77
            wrote on last edited by
            #5

            Thanks, I have solved it now.

            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