PDA

View Full Version : Formatting QString



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?.

Lykurg
10th September 2011, 12:50
Read the docs about QSqlQuery::prepare() again. Use QSqlQuery::bindValue()...

Then use a QStringList and see QStringList::join().

thefatladysingsopera
11th September 2011, 17:16
No need for writing the delete query,the function works fine with OnRowChange mode.