Results 1 to 4 of 4

Thread: QsqlTableModel not fetching all rows after update

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Jan 2012
    Location
    Argentina
    Posts
    167
    Thanks
    33
    Thanked 10 Times in 10 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QsqlTableModel not fetching all rows after update

    Thank you for replying. Line 51 modified :P

    I tried calling the reset but nothing changes. Rows showed change to 256 after the edit.

    There is no selection, the user only changes the value of one cell so i think i dont have to iterate, right? So i call setData() from the index of interest but still the same, rows trim to 256.

    Qt Code:
    1. void WidgetModificacion::actualizar_fecha (int row, QSqlRecord & record){
    2. if (tipo_tabla == 0){
    3. QSqlQuery query = QSqlQuery (db);
    4. query.prepare("UPDATE TABLE_PRODUCTOS SET fecha_modificacion = SYSDATE WHERE id_codigo_barra = :value");
    5. query.bindValue (":value", this->ui->tableView->model ()->data (this->ui->tableView->model ()->index (row, 0)).toString ());
    6. query.exec ();
    7. }
    8. //ui->tableView->reset();
    9. model->setData(model->index(row,5), QDateTime::currentDateTime().toString(),Qt::DisplayRole);
    10. while (model->canFetchMore())model->fetchMore();
    11. }
    To copy to clipboard, switch view to plain text mode 

    The value is always updated after edit and i can see that value modified but rows set to 256 anyways.

  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: QsqlTableModel not fetching all rows after update

    You reset the QSqlTableModel and it re-executes the underlying query and, as always, fetches rows lazily. If you want to fetch all the rows again then use canFetchMore() and fetchMore().

    If you are only updating a single cell then look up its QModelIndex and call setData() and the view will look after itself. Exactly when that update is written to the underlying database and the effect on selections/current cell is a function of the model's edit strategy.

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

    KillGabio (17th July 2013)

Similar Threads

  1. Replies: 0
    Last Post: 11th October 2012, 10:25
  2. Sum of rows in QSqlTableModel
    By aekilic in forum Qt Programming
    Replies: 2
    Last Post: 24th October 2010, 20:05
  3. Replies: 2
    Last Post: 25th January 2010, 20:56
  4. QSqlTableModel inserts empty rows
    By Nesbitt in forum Qt Programming
    Replies: 2
    Last Post: 6th August 2008, 12:47
  5. Fetching rows in QtreeView
    By visor_ua in forum Qt Programming
    Replies: 2
    Last Post: 5th July 2008, 18:17

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
  •  
Qt is a trademark of The Qt Company.