当使用指向有效垂直标题项的指针调用QTableWidget::row( const QTableWidgetItem * item )
时,函数返回-1
. 不过我不希望这样,因为我通过调用将表格小部件中行的垂直标题项显式设置为指针指向的项QTableWidget::setVerticalHeaderItem ( int row, QTableWidgetItem * item )
。
示例代码:
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 ) );
为什么使用verticalHeaderItem
地址检索行会返回无效行-1
?