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. model populated signal

model populated signal

Scheduled Pinned Locked Moved Solved General and Desktop
18 Posts 2 Posters 4.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 VRonin

    @user4592357 said in model populated signal:

    i need to know when data is available

    Could you provide a small example of what you mean?

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

    @VRonin

    table = new TableView();
    table->setModel(new TableModel);
    // ...
    // here i need some way to be able to know when data is put into model
    connect(table, /* some signal */, [this] { ( /* update gui */) });
    
    1 Reply Last reply
    0
    • VRoninV Offline
      VRoninV Offline
      VRonin
      wrote on last edited by
      #4

      like QAbstractItemModel::dataChanged?

      "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

        like QAbstractItemModel::dataChanged?

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

        @VRonin
        is that the correct one to use?

        it didn't activate the slot

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

          You were really vague on what your needs are but that is the one closer to your description.
          QTableView already uses that signal to know when to repaint so you could do the same

          "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

          1 Reply Last reply
          0
          • U user4592357

            @VRonin
            is that the correct one to use?

            it didn't activate the slot

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

            @user4592357 said in model populated signal:

            it didn't activate the slot

            That means you didn't implement the model correctly, see http://doc.qt.io/qt-5/qabstractitemmodel.html#subclassing it's not easy :)

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

              it didn't activate the slot

              That means you didn't implement the model correctly, see http://doc.qt.io/qt-5/qabstractitemmodel.html#subclassing it's not easy :)

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

              @VRonin
              do you mean emitting dataChanged()? my model isn't editable so i don't need it

              1 Reply Last reply
              0
              • 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 Extensions
                                  • Unsolved