Results 1 to 3 of 3

Thread: QSqlQueryModel ‘s method rowcount() return 256

  1. #1
    Join Date
    Apr 2013
    Posts
    3
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11

    Default QSqlQueryModel ‘s method rowcount() return 256

    there are 1000 record in my database table,but when i use querymodel binding the tableview, there are 1000 records displaying in the tableview,but the querymodel.rowcount() return 256,why?thanks! the code as follows:

    Qt Code:
    1.  
    2. QSqlQuery query;
    3. QString querystr = "select * from mytable";
    4.  
    5.  
    6. query.exec();
    7.  
    8. model->setQuery(query);
    9. model->setHeaderData(1, Qt::Horizontal, tr("name"));
    10. model->setHeaderData(2, Qt::Horizontal, tr("age"));
    11.  
    12. ui->tableViewZDCommTask->setModel(model);
    13. ui->tableViewZDCommTask->setSelectionMode(QAbstractItemView::MultiSelection);
    14. ui->tableViewZDCommTask->setSelectionBehavior(QAbstractItemView::SelectRows);
    15. ui->tableViewZDCommTask->setColumnHidden(0,true);
    16. ui->tableViewZDCommTask->resizeColumnsToContents();
    17. ui->tableViewZDCommTask->setEditTriggers(QAbstractItemView::NoEditTriggers);
    18.  
    19. QHeaderView *header = ui->tableViewZDCommTask->horizontalHeader();
    20. header->setStretchLastSection(true);
    21. ui->tableViewZDCommTask->show();
    22.  
    23. QMessageBox::about(0,"",QString::number(model->rowCount()));//return 256[/INDENT]
    To copy to clipboard, switch view to plain text mode 

  2. #2
    Join Date
    Mar 2008
    Location
    Kraków, Poland
    Posts
    1,536
    Thanked 284 Times in 279 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QSqlQueryModel ‘s method rowcount() return 256

    Did You read how this method work ? Doc says : If the database supports returning the size of a query (see QSqlDriver::hasFeature()), the number of rows of the current query is returned. Otherwise, returns the number of rows currently cached on the client..
    As you can see the result is dependent on what can your database.

  3. #3
    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: QSqlQueryModel ‘s method rowcount() return 256

    QSqlQueryModel, on which QTableModel is built, is hard coded to prefetch 255 rows at a time. Look at the canFetchMore() and fetchMore() methods.

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

    aker (17th September 2013)

Similar Threads

  1. Replies: 6
    Last Post: 22nd May 2011, 09:52
  2. problem with rowCount method
    By sergio486 in forum Qt Programming
    Replies: 2
    Last Post: 18th December 2010, 08:37
  3. A method that return a struct
    By PaceyIV in forum General Programming
    Replies: 5
    Last Post: 18th July 2009, 12:08
  4. Replies: 7
    Last Post: 18th November 2008, 17:17
  5. rowCount and model
    By steg90 in forum Newbie
    Replies: 3
    Last Post: 11th May 2007, 09:14

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.