Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-70478

cellChanged signal generated by QTableWidget::takeItem() always has row and column set to -1

    XMLWordPrintable

Details

    • c18a91b0dc5e82c0624758a6300f561e36b968fc

    Description

      • 1. Create a QTableWidget instance.
        2. Create an item at, say, coordinates column 5, row 3.
        3. Hook up a slot to cellChanged signal of the table widget.
        3. Call takeItem() with the same coordinates.

      Expected: the slot gets invoked with row = 3, column = 5
      Actual: it does get invoked, but row and column are set to -1

      Per my understanding here is why (from qtablewidget.cpp):

      QTableWidgetItem *QTableModel::takeItem(int row, int column)
      {
          long i = tableIndex(row, column);
          QTableWidgetItem *itm = tableItems.value(i);
          if (itm) {
              itm->view = 0;
              itm->d->id = -1;
              tableItems[i] = 0;
              QModelIndex ind = index(itm);
              emit dataChanged(ind, ind);
          }
          return itm;
      }
      

      Note that itm is taken from tableItems vector, then both are modified to essentially forget about each other, and then ind = index(itm) looks back into tableItems vector to find the item, naturally doesn't find anything and returns QModelIndex(), i.e. a default constructor, and sends that to the dataChanged signal.

      Attachments

        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

        Activity

          People

            chehrlic Christian Ehrlicher
            alex.verkhovsky Alex Verkhovsky
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes