Results 1 to 2 of 2

Thread: QSqlQuery: remove a record

  1. #1
    Join Date
    May 2014
    Posts
    1
    Platforms
    Unix/X11 Windows

    Default QSqlQuery: remove a record

    I tried removing some records from QSqlQuery using query.record().remove(pos) but it doesn't work at all. Is there any way to remove the record from QSqlQuery? I know about QSqlQueryModel, but I would like to use QSqlQuery, because it works fine for my application.

    There is the code:
    Qt Code:
    1. #include "QtSql/QtSql"
    2. #include "QtSql/QSqlRecord"
    3.  
    4. QString sql_str;
    5. sql_str = "select * from param";
    6. QSqlQuery query;
    7. query.prepare(sql_str);
    8. query.exec();
    9.  
    10. int index=0;
    11.  
    12. query.seek(-1);
    13.  
    14. while(query.next()){
    15. query.record().clear();
    16. query.record().clearValues();
    17. query.record().remove(0);
    18. ui->tableWidget_2->setItem(index,0,new QTableWidgetItem(query.record().value(0).toString()));
    19. ui->tableWidget_2->setItem(index,1,new QTableWidgetItem(query.value(1).toString()));
    20. ui->tableWidget_2->setItem(index,2,new QTableWidgetItem(query.value(2).toString()));
    21. ui->tableWidget_2->setItem(index,3,new QTableWidgetItem(query.value(3).toString()));
    22. index++;
    23. }
    To copy to clipboard, switch view to plain text mode 

    I use Qt Creator 1.3.0 based on Qt 4.6.0 (32-bit)
    Nov 27 2009 at 14:53:38
    Revision c0e849ecc3

  2. #2
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: QSqlQuery: remove a record

    It is difficult to work out what you are trying to achieve, but none of your calls to QSqlRecord::clear() and friends will have any effect on the data seen in the code following. These calls are all operating on a temporary QSqlRecord that you discard immediately.
    If you do not want the first column in the result set then do not select it in the first place ("SELECT *" is a construct that should generally be avoided anyway). Alternatively, just ignore index zero and load your from query.value(1) on.

Similar Threads

  1. Replies: 2
    Last Post: 25th June 2012, 11:54
  2. Replies: 2
    Last Post: 25th January 2011, 11:17
  3. Replies: 7
    Last Post: 27th November 2010, 16:55
  4. Replies: 4
    Last Post: 23rd October 2010, 18:54
  5. Replies: 3
    Last Post: 26th March 2010, 05:32

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.