thefatladysingsopera
10th September 2011, 12:22
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();
How will write the 'rows' part?.
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();
How will write the 'rows' part?.