Results 1 to 3 of 3

Thread: Formatting QString

  1. #1
    Join Date
    Apr 2011
    Posts
    67
    Thanks
    22
    Thanked 5 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Formatting QString

    I want to delete multiple rows from QTableView and i have the code below.

    Qt Code:
    1. QItemSelection selection( ui.tableView->selectionModel()->selection() );
    2. QList<int> rows;
    3. foreach( const QModelIndex & index, selection.indexes() ) {
    4. rows.append( index.row() );
    5. }
    6.  
    7. qSort( rows );
    8.  
    9. int prev = -1;
    10. for( int i = rows.count() - 1; i >= 0; i -= 1 ) {
    11. int current = rows[i];
    12. if( current != prev ) {
    13. tableModel->removeRows( current, 1 );
    14. prev = current;
    15. }
    16. }
    17.  
    18. QString sqlQuery = QString("DELETE FROM %1 WHERE id IN ('rows')").arg(tableName);
    19. //.arg( 1, 2, 3 ). or .arg( x ).arg( y ).arg( z )
    20. query.prepare(sqlQuery);
    21. query.exec();
    To copy to clipboard, switch view to plain text mode 
    How will write the 'rows' part?.

  2. #2
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: Formatting QString

    Read the docs about QSqlQuery::prepare() again. Use QSqlQuery::bindValue()...

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

  3. The following user says thank you to Lykurg for this useful post:

    thefatladysingsopera (10th September 2011)

  4. #3
    Join Date
    Apr 2011
    Posts
    67
    Thanks
    22
    Thanked 5 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Formatting QString

    No need for writing the delete query,the function works fine with OnRowChange mode.

Similar Threads

  1. Replies: 2
    Last Post: 11th August 2011, 15:42
  2. QString formatting issue.
    By George Neil in forum Qt Programming
    Replies: 2
    Last Post: 22nd October 2009, 09:00
  3. Replies: 4
    Last Post: 31st January 2008, 20:44
  4. Formatting a QString
    By icentenee in forum Newbie
    Replies: 9
    Last Post: 1st October 2006, 17:41
  5. QString formatting
    By brcain in forum Qt Programming
    Replies: 1
    Last Post: 27th September 2006, 03:00

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.