When calling QTableWidget::row( const QTableWidgetItem * item )
with a pointer to a valid vertical header item, the function is returning -1
. I wouldn't expect this though, since I explicitly set the vertical header item of the row in the table widget to the item pointed to by the pointer by calling QTableWidget::setVerticalHeaderItem ( int row, QTableWidgetItem * item )
.
Example code:
qint32 newRow = ui->tableWidget->rowCount();
ui->tableWidget->insertRow( newRow );
QTableWidgetItem *vertHeadItem = new QTableWidgetItem( "Row Header" );
ui->tableWidget->setVerticalHeaderItem( newRow, vertHeadItem );
/* these two outputs print the same address, as expected */
// output is 0xb855b90
qDebug() << vertHeadItem;
// output is 0xb855b90
qDebug() << ui->tableWidget->verticalHeaderItem( newRow );
/* These two outputs are not the same, but I would expect them to be */
// output is "4"
qDebug() << newRow; // this is the row that contains the verticalHeaderItem
// output is "-1"
qDebug() << ui->tableWidget->row( ui->tableWidget->verticalHeaderItem( newRow ) );
Why does retrieving the row using the verticalHeaderItem
address return an invalid row of -1
?