Results 1 to 3 of 3

Thread: How to disable "lasy population" in QSqlRelationalTableModel?

  1. #1
    Join Date
    Oct 2012
    Posts
    2
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Windows

    Question How to disable "lasy population" in QSqlRelationalTableModel?

    Hello!
    I'm creating a model, connected with a db-table from SQlite and show it using tableView. Here is my code:
    Qt Code:
    1. model->setTable("publications");
    2. model->setRelation(6, QSqlRelation("pub_types", "id", "type"));
    3. model->setEditStrategy(QSqlTableModel::OnFieldChange);
    4. model->select();
    5. while(model->canFetchMore())
    6. model->fetchMore();
    7. ui->tableView_pub->setModel(model);
    8. ui->tableView_pub->setFocus();
    9. ui->tableView_pub->selectRow(model->rowCount()-1);
    To copy to clipboard, switch view to plain text mode 
    QSqlRelationalTableModel class is implemented with a so-called "lazy population". When i'm working with table, it loads only first 255 rows from database, and the rest only after scrolling. I don't need it, I want to load all data at once (there is enough memory and database is not too large)
    Everywhere I can, I use this code: "while(model->canFetchMore()) model->fetchMore();". It works just fine, tableview always loads all data at once.
    However, I also need to use OnFieldChange editing strategy. Herewith, when user finishes editing of a cell from a row with number more than 255, table in database changes, and tableview load data again. But, this time I can't insert my "while(model->canFetchMore()) model->fetchMore();" anywhere, because it is hidden somewhere inside the class. As a result, after editing tableView jumps to 255-th row. This is very inconvinient.
    My question is, how to change this situation? How to change methods of QSqlRelationalTableModel to load all data at once, or somehow increase this 255-rows limit?

  2. #2
    Join Date
    Sep 2012
    Location
    Iran, Tehran
    Posts
    76
    Thanks
    17
    Thanked 13 Times in 13 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Windows

    Default Re: How to disable "lasy population" in QSqlRelationalTableModel?

    In this case you can implement a slot which loads all the data and connect the QAbstractItemModel::dataChanged signal of the model to it.


    Added after 22 minutes:


    You may also try to subclass the QSqlRelationalTableModel and re-implement its QSqlRelationalTableModel::select method and fetch all the data here or emit some signal you have defined and then connect the signal to a slot which loads all the data. seems working.
    Last edited by Ashkan_s; 18th October 2012 at 21:09.

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

    Husky (19th October 2012)

  4. #3
    Join Date
    Oct 2012
    Posts
    2
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: How to disable "lasy population" in QSqlRelationalTableModel?

    Thanks a lot!
    I subclassed my own class QSqlRelationalTableModelExtraFetch from QSqlRelationalTableModel and reimplemented select() this way:
    Qt Code:
    1. bool QSqlRelationalTableModelExtraFetch::select()
    2. {
    3. bool result;
    4. result = QSqlTableModel::select();
    5. while(this->canFetchMore())
    6. this->fetchMore();
    7. return result;
    8. }
    To copy to clipboard, switch view to plain text mode 

    Just what I need.

Similar Threads

  1. How to disable "app not responding dialog" [QML- MeeGo Harmattan PR1.2]
    By aya_lawliet in forum Qt for Embedded and Mobile
    Replies: 4
    Last Post: 14th May 2012, 12:37
  2. Replies: 3
    Last Post: 15th February 2010, 18:27
  3. Replies: 3
    Last Post: 8th July 2008, 20:37
  4. Translation QFileDialog standart buttons ("Open"/"Save"/"Cancel")
    By victor.yacovlev in forum Qt Programming
    Replies: 4
    Last Post: 24th January 2008, 20:05
  5. QFile Problem~ "Unknow error" in "open(QIODevice::ReadWrite)"
    By fengtian.we in forum Qt Programming
    Replies: 3
    Last Post: 23rd May 2007, 16:58

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.