【发布时间】:2011-09-10 16:17:00
【问题描述】:
在寻找关于如何从 QTableView 中删除多行的线索时,我遇到了这个函数:remove selected rows from QTableView
这里是代码:-
QItemSelection selection( ui.tableView->selectionModel()->selection() );
QList<int> rows;
foreach( const QModelIndex & index, selection.indexes() ) {
rows.append( index.row() );
}
qSort( rows );
int prev = -1;
for( int i = rows.count() - 1; i >= 0; i -= 1 ) {
int current = rows[i];
if( current != prev ) {
tableModel->removeRows( current, 1 );
prev = current;
}
}
我需要帮助编写查询。我一直在尝试这个:-
query.exec(QString("DELETE FROM %1 id IN %2").arg(tableName,rows));
但我认为我应该在某处使用 QStringList,但我仍在阅读 QList 示例。有人吗?。
【问题讨论】: