Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt
  • Unsolved
Collapse
qtws26_logo

The Qt Event of the Year: Qt World Summit 2026

Save Your Spot >
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. model populated signal
Qt 6.12 LTS is out! See what's new in the release blog

model populated signal

Scheduled Pinned Locked Moved Solved General and Desktop
18 Posts 2 Posters 6.2k 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.
  • VRoninV Offline
    VRoninV Offline
    VRonin
    wrote on last edited by
    #9

    The fact the is editable or not is meaningless, if any change in your model should trigger a repaint in the view you should emit that signal

    "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
    ~Napoleon Bonaparte

    On a crusade to banish setIndexWidget() from the holy land of Qt

    U 1 Reply Last reply
    0
    • VRoninV VRonin

      The fact the is editable or not is meaningless, if any change in your model should trigger a repaint in the view you should emit that signal

      U Offline
      U Offline
      user4592357
      wrote on last edited by
      #10

      @VRonin
      still no luck :(

      1 Reply Last reply
      0
      • VRoninV Offline
        VRoninV Offline
        VRonin
        wrote on last edited by
        #11

        Can you post your model implementation?

        "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
        ~Napoleon Bonaparte

        On a crusade to banish setIndexWidget() from the holy land of Qt

        U 1 Reply Last reply
        0
        • VRoninV VRonin

          Can you post your model implementation?

          U Offline
          U Offline
          user4592357
          wrote on last edited by user4592357
          #12

          @VRonin
          sorry it's python. nothing specific to it, though.

          class TableModel(QAbstractTableModel):
          	headers = [/* items */]
          
          	def __init__(self, parent=None):
          		super(TableModel, self).__init__(parent)
          		self.__data = []
          
          	def rowCount(self, parent=QModelIndex()):
          		del parent
          		return len(self.__data)
          
          	def columnCount(self, parent=QModelIndex()):
          		del parent
          		return len(self.headers)
          
          	def data(self, index, role=Qt.DisplayRole):
          		if not index.isValid() or \
          				not (0 <= index.row() < self.rowCount()) or \
          				not (0 <= index.column() < self.columnCount()):
          			return QVariant()
          
          		if role == Qt.DisplayRole:
          			return self.__data[index.row()][index.column()]
          
          		if role == Qt.UserRole:
          			return self.__data[index.row()][0]
          
          		return QVariant()
          
          	def headerData(self, section, orientation, role):
          		if role != Qt.DisplayRole:
          			return QVariant()
          
          		if orientation == Qt.Horizontal:
          			return self.headers[section]
          
          		return section + 1
          
          	def set_data(self, data):
          		self.beginResetModel()
          
          		del self.__data[:]
          
                          # populate self.__data
          
          		self.endResetModel()
          
          		self.dataChanged.emit(self.index(0, 0), self.index(self.rowCount() - 1, self.columnCount() - 1))
          
          
          1 Reply Last reply
          0
          • VRoninV Offline
            VRoninV Offline
            VRonin
            wrote on last edited by
            #13

            You are using reset model so you can connect to QAbstractItemModel::modelReset

            "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
            ~Napoleon Bonaparte

            On a crusade to banish setIndexWidget() from the holy land of Qt

            U 1 Reply Last reply
            0
            • VRoninV VRonin

              You are using reset model so you can connect to QAbstractItemModel::modelReset

              U Offline
              U Offline
              user4592357
              wrote on last edited by user4592357
              #14

              @VRonin
              that's what i tried first

              actually, the first time model is populated, the slot isn't invoked, but when it's populated 2nd time, the slot is invoked (with both signals)

              VRoninV 1 Reply Last reply
              0
              • U user4592357

                @VRonin
                that's what i tried first

                actually, the first time model is populated, the slot isn't invoked, but when it's populated 2nd time, the slot is invoked (with both signals)

                VRoninV Offline
                VRoninV Offline
                VRonin
                wrote on last edited by
                #15

                @user4592357 said in model populated signal:

                the slot isn't invoked

                Doubt

                from https://code.woboq.org/qt5/qtbase/src/corelib/itemmodels/qabstractitemmodel.cpp.html#_ZN18QAbstractItemModel13endResetModelEv:

                void QAbstractItemModel::endResetModel()
                {
                    Q_D(QAbstractItemModel);
                    d->invalidatePersistentIndexes();
                    QMetaObject::invokeMethod(this, "resetInternalData");
                    emit modelReset(QPrivateSignal());
                }
                

                "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
                ~Napoleon Bonaparte

                On a crusade to banish setIndexWidget() from the holy land of Qt

                U 1 Reply Last reply
                0
                • VRoninV VRonin

                  @user4592357 said in model populated signal:

                  the slot isn't invoked

                  Doubt

                  from https://code.woboq.org/qt5/qtbase/src/corelib/itemmodels/qabstractitemmodel.cpp.html#_ZN18QAbstractItemModel13endResetModelEv:

                  void QAbstractItemModel::endResetModel()
                  {
                      Q_D(QAbstractItemModel);
                      d->invalidatePersistentIndexes();
                      QMetaObject::invokeMethod(this, "resetInternalData");
                      emit modelReset(QPrivateSignal());
                  }
                  
                  U Offline
                  U Offline
                  user4592357
                  wrote on last edited by
                  #16

                  @VRonin
                  yeah

                  another weird thing: the 2nd time it's invoked, 3rd time it's invoked twice, 4th time - thrice, etc...

                  1 Reply Last reply
                  0
                  • VRoninV Offline
                    VRoninV Offline
                    VRonin
                    wrote on last edited by
                    #17

                    Where are you connecting the signal? looks like you are connecting every time it's invoked

                    "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
                    ~Napoleon Bonaparte

                    On a crusade to banish setIndexWidget() from the holy land of Qt

                    U 1 Reply Last reply
                    3
                    • VRoninV VRonin

                      Where are you connecting the signal? looks like you are connecting every time it's invoked

                      U Offline
                      U Offline
                      user4592357
                      wrote on last edited by
                      #18

                      @VRonin
                      my bad, right...

                      how didn't i realize? thanks

                      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
                      • Unsolved