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. The model inherited from QAbstractTableModel throws errors

The model inherited from QAbstractTableModel throws errors

Scheduled Pinned Locked Moved Solved General and Desktop
18 Posts 3 Posters 1.8k 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.
  • Christian EhrlicherC Offline
    Christian EhrlicherC Offline
    Christian Ehrlicher
    Lifetime Qt Champion
    wrote on last edited by
    #9

    @Mikeeeeee said in The model inherited from QAbstractTableModel throws errors:

    What is the bug and how to fix it?

    Christian Ehrlicher 18 minutes ago

    And you should only return values for Qt::DisplayRole

    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
    • M Offline
      M Offline
      Mikeeeeee
      wrote on last edited by
      #10

      I fixed the code, there is no more error. But the column index is always zero. I don't understand how to fix this. Debag returns:
      0 0
      0 0
      0 0
      Model size of -3 is less than 0
      0 1
      0 1
      0 1
      0 2
      0 2
      0 2

      Christian EhrlicherC 1 Reply Last reply
      0
      • M Offline
        M Offline
        Mikeeeeee
        wrote on last edited by
        #11

        1.png

        1 Reply Last reply
        0
        • M Mikeeeeee

          I fixed the code, there is no more error. But the column index is always zero. I don't understand how to fix this. Debag returns:
          0 0
          0 0
          0 0
          Model size of -3 is less than 0
          0 1
          0 1
          0 1
          0 2
          0 2
          0 2

          Christian EhrlicherC Offline
          Christian EhrlicherC Offline
          Christian Ehrlicher
          Lifetime Qt Champion
          wrote on last edited by
          #12

          @Mikeeeeee said in The model inherited from QAbstractTableModel throws errors:

          I fixed the code

          Please update your code in your example so we can see what you're doing.

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

          M 1 Reply Last reply
          0
          • M Offline
            M Offline
            Mikeeeeee
            wrote on last edited by
            #13
            This post is deleted!
            1 Reply Last reply
            0
            • Christian EhrlicherC Christian Ehrlicher

              @Mikeeeeee said in The model inherited from QAbstractTableModel throws errors:

              I fixed the code

              Please update your code in your example so we can see what you're doing.

              M Offline
              M Offline
              Mikeeeeee
              wrote on last edited by
              #14

              @Christian-Ehrlicher I updated the code an hour ago. I didn't add anything after that.

              1 Reply Last reply
              0
              • M Offline
                M Offline
                Mikeeeeee
                wrote on last edited by
                #15

                Maybe the problem is in QML?

                import QtQuick 2.13
                import QtQuick.Controls 1.4
                
                Item {
                    width: 380
                    height: 680
                
                    TableView {
                        anchors.fill: parent
                        TableViewColumn {
                            role: "role1"
                            title: "Column1"
                            width: 100
                        }
                        TableViewColumn {
                            role: "role2"
                            title: "Column2"
                            width: 100
                        }
                        TableViewColumn {
                            role: "role3"
                            title: "Column3"
                            width: 100
                        }
                        model: myModel
                    }
                
                }
                
                1 Reply Last reply
                0
                • Christian EhrlicherC Offline
                  Christian EhrlicherC Offline
                  Christian Ehrlicher
                  Lifetime Qt Champion
                  wrote on last edited by
                  #16

                  Then you still did not read my comment about the Qt::DisplayRole. So stay on your own.

                  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
                  • M Offline
                    M Offline
                    Mikeeeeee
                    wrote on last edited by
                    #17

                    I don't understand what you mean. Please answer in more detail and clearly.

                    1 Reply Last reply
                    0
                    • M Offline
                      M Offline
                      Mikeeeeee
                      wrote on last edited by
                      #18

                      Its work

                      QVariant MyModel::data(const QModelIndex & index, int role) const {
                          if (index.row() < 0 || index.row() >= list1.count())
                              return QVariant();
                          if(role == 0){
                              return QVariant(list1[index.row()]);
                          }
                          if(role == 1){
                              return QVariant(list2[index.row()]);
                          }
                          if(role == 2){
                              return QVariant(list3[index.row()]);
                          }
                          return QVariant();
                      }
                      
                      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