I want to delete multiple rows from QTableView and i have the code below.
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;
}
}
QString sqlQuery
= QString("DELETE FROM %1 WHERE id IN ('rows')").
arg(tableName
);
//.arg( 1, 2, 3 ). or .arg( x ).arg( y ).arg( z )
query.prepare(sqlQuery);
query.exec();
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;
}
}
QString sqlQuery = QString("DELETE FROM %1 WHERE id IN ('rows')").arg(tableName);
//.arg( 1, 2, 3 ). or .arg( x ).arg( y ).arg( z )
query.prepare(sqlQuery);
query.exec();
To copy to clipboard, switch view to plain text mode
How will write the 'rows' part?.
Bookmarks