Results 1 to 4 of 4

Thread: QtSqlQueryModel removeRow's problem

  1. #1
    Join Date
    Feb 2008
    Posts
    2

    Question QtSqlQueryModel removeRow's problem

    hi guys,I had to ask for help.thanks advance!
    my problem is the removeRow method in mycode never succeed:

    Qt Code:
    1. model->setQuery("select * from person");
    2. QTableView *view = new QTableView;
    3. view->setModel(model);
    To copy to clipboard, switch view to plain text mode 

    ok,I can get 7 rows from the person table.
    now I try
    Qt Code:
    1. model->removeRow(0);
    2. model->removeRow(1);
    3. ...
    To copy to clipboard, switch view to plain text mode 
    however,It donse't work。everything in the view still stay.

    but if I use the flowing code:
    Qt Code:
    1. plainModel.setTable("person");
    2. plainModel.select();
    3. QTableView *view = new QTableView;
    4. view->setModel(&plaiModel);
    5.  
    6. plainModel.removeRow(0);
    To copy to clipboard, switch view to plain text mode 

    Ok,It works. there is 6 rows left in the view.

    so ,whats my problem in my first case? how can i resolve it?
    need i change any thing from QSqlQueryModel to QSqlRelationTableModel?
    but I would like to use setQuery method than setTable method.

    so ,give a help ,please.

    thx
    Last edited by jpn; 25th February 2008 at 19:46. Reason: missing [code] tags

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QtSqlQueryModel removeRow's problem

    QSqlQueryModel is a read only model, you can't remove rows from it.

  3. #3
    Join Date
    Feb 2008
    Posts
    2

    Thumbs up Re: QtSqlQueryModel removeRow's problem

    yeah, with QSqlQueryModel read only.
    I want to have something ,

    perhaps I have 7 rows in the table,
    I just want to delete some rows from the QTableView,
    not delete the record in the database,how can I do??

    can u give me a point? thx

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QtSqlQueryModel removeRow's problem

    Apply a QSortFilterProxyModel or set a condition on the query so that you only retrieve the rows you need from the database.

Similar Threads

  1. Replies: 16
    Last Post: 7th March 2006, 15:57

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.