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. Some questions about the QAbstractTableModel dataChanged signal
Qt 6.11 is out! See what's new in the release blog

Some questions about the QAbstractTableModel dataChanged signal

Scheduled Pinned Locked Moved Unsolved General and Desktop
7 Posts 3 Posters 2.1k 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.
  • A Offline
    A Offline
    andi456
    wrote on last edited by
    #1

    Hi,

    in my project centered around tableviews and abstracttablemodels, whose number is being determined by loading some json-data, i have some rows consisting of boolean values. The ones set to "true" get counted and displayed in the last row but the result will not be shown, because I somehow can't figure out the correct syntax for it. I suppose that usually only one cell is being updated, when the signal from the setData function is being emitted like this:

    emit dataChanged(index, index); 
    

    But I want to be able to also display the value on the same column and the last line, so something like:

    emit dataChanged(index(row, col), index(lastRow, col)); ```
    
    

    should work. But I encounter a "No matching call error".

    The other question is related to the first. For some of the boolean columns i'd like to know how many cells are being set to true regarding all tableviews / abstracttablemodels. What might be the best way to achieve this? Connecting to the dataChanged signals of all the other models? Or would it be more suitable to add a custom signal?

    Kind regards,

    Andreas

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

      Any chance you have a local variable named index and that you are trying to call the function of the same name ?

      As your multiple models, yes, you can connect to the dataChanged signal and only act if the change includes one or more of your Boolean column.

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      A 1 Reply Last reply
      2
      • SGaistS SGaist

        Hi,

        Any chance you have a local variable named index and that you are trying to call the function of the same name ?

        As your multiple models, yes, you can connect to the dataChanged signal and only act if the change includes one or more of your Boolean column.

        A Offline
        A Offline
        andi456
        wrote on last edited by
        #3

        @SGaist well it should be the index parameter of setData(const QModelIndex &index, const QVariant &value, int role), i suppose. Or should I declare another QModelIndex locally?

        Regarding the connection to the dataChanged signals, i must think about how to avoid too much confusion, because, if one value changes, all the other tables must be affected....

        1 Reply Last reply
        0
        • A Offline
          A Offline
          andi456
          wrote on last edited by andi456
          #4

          Ok, after a look into the documentation, i could solve the first question. I added a local QModelIndex() and assigned the index variable of the model to it:

          code_t QModelIndex bottomRight = this->index(lastRow, col, QModelIndex());
          

          I don't know why i cannot use the parameter of the function itself, because i found a lot of examples suggesting just that. Anyway, the dataChanged function now works as expected and looks like this in my case:

          emit dataChanged(index, bottomRight);
          
          1 Reply Last reply
          0
          • Christian EhrlicherC Offline
            Christian EhrlicherC Offline
            Christian Ehrlicher
            Lifetime Qt Champion
            wrote on last edited by
            #5

            @andi456 said in Some questions about the QAbstractTableModel dataChanged signal:

            I don't now why i cannot use the parameter of the function itself,

            The one is a parameter of type QModelIndex, the other a function from QAbstractItemModel.

            Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
            Visit the Qt Academy at https://academy.qt.io/catalog

            A 1 Reply Last reply
            2
            • Christian EhrlicherC Christian Ehrlicher

              @andi456 said in Some questions about the QAbstractTableModel dataChanged signal:

              I don't now why i cannot use the parameter of the function itself,

              The one is a parameter of type QModelIndex, the other a function from QAbstractItemModel.

              A Offline
              A Offline
              andi456
              wrote on last edited by
              #6

              @Christian-Ehrlicher Thanks for the clarification. Anyway, there're examples on the internet that seem to suggest that one could also use the parameter of setData() in order to obtain the same thing.

              1 Reply Last reply
              0
              • Christian EhrlicherC Offline
                Christian EhrlicherC Offline
                Christian Ehrlicher
                Lifetime Qt Champion
                wrote on last edited by
                #7

                It depends on what you want to do...

                Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
                Visit the Qt Academy at https://academy.qt.io/catalog

                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