Results 1 to 6 of 6

Thread: Question about method named rowCount() of QSqlTableModel

  1. #1
    Join Date
    Jan 2014
    Posts
    20
    Thanks
    2
    Qt products
    Qt5
    Platforms
    Unix/X11 Windows

    Default Question about method named rowCount() of QSqlTableModel

    Hi all,
    After i use QSqlTableModel to get one table in database, i want to handle every row in table ,so i code as follows:
    Qt Code:
    1. QSqlTableModel tableModel;
    2. tableModel->setTable(tableA);
    3. tableModel->select();
    4. int nCount = tableModel->rowCount();
    5. for(int i=0, i<nCount, i++)
    6. {
    7. // handle every row
    8. // ....
    9. }
    To copy to clipboard, switch view to plain text mode 
    here is my question, why the value of nCount is less than the real rows' count(Observed from database table view)? And the value is 256, could i get whole rows when the count of rows are so many like tens of thousands? Or is there any smarter idea to do the same work?
    Thank you!

  2. #2
    Join Date
    May 2012
    Posts
    136
    Thanks
    2
    Thanked 27 Times in 24 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Question about method named rowCount() of QSqlTableModel

    it is possible that nCount is different than the real rows in the database (this behaviour is described in the manual)
    from the manual:
    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.

    if there is a smarter way, depends on what you try to accomplish

  3. #3
    Join Date
    Jan 2014
    Posts
    20
    Thanks
    2
    Qt products
    Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Question about method named rowCount() of QSqlTableModel

    Quote Originally Posted by StrikeByte View Post
    it is possible that nCount is different than the real rows in the database (this behaviour is described in the manual)
    from the manual:
    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.

    if there is a smarter way, depends on what you try to accomplish
    Thank you so much!
    could you tell me where the behaviour is described ? i can't find in the help doc, maybe i'm not careful enough.
    I use Oracle database, if it supports returning the size of a query and how?
    I also think if i can change the cached to get more number of rows, but it doesn't seem a good way...

    Thx again!

  4. #4
    Join Date
    May 2012
    Posts
    136
    Thanks
    2
    Thanked 27 Times in 24 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Question about method named rowCount() of QSqlTableModel

    The behaviour is described in http://qt-project.org/doc/qt-4.8/qsq....html#rowCount
    To see if it supports returning the size you can use the hasFeature() function (there is a link to the function in the rowcount documentation)
    To get all rows you can do a sql select that returns all rows (SELECT * FROM tablename) you can replace * with a column name u need

    If you don't mind me asking why do you want to get a count of all rows?

  5. #5
    Join Date
    Jan 2014
    Posts
    20
    Thanks
    2
    Qt products
    Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Question about method named rowCount() of QSqlTableModel

    Quote Originally Posted by StrikeByte View Post
    The behaviour is described in http://qt-project.org/doc/qt-4.8/qsq....html#rowCount
    To see if it supports returning the size you can use the hasFeature() function (there is a link to the function in the rowcount documentation)
    To get all rows you can do a sql select that returns all rows (SELECT * FROM tablename) you can replace * with a column name u need

    If you don't mind me asking why do you want to get a count of all rows?
    Thank you first! sorry for reply late,I just see it。
    To get all rows,I can handle every row though a loop(eg· for(int i=0;i<rowcount;i++))
    Is there any better idea to traverse a table without rowcount of qsqltablemodel?thanks!

  6. #6
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Question about method named rowCount() of QSqlTableModel

    You can use QSqlQuery directly.

    Cheers,
    _

Similar Threads

  1. Question about method named record() in QSqlTableModel
    By silentyears in forum Qt Programming
    Replies: 7
    Last Post: 21st January 2014, 10:52
  2. QSqlQueryModel ‘s method rowcount() return 256
    By liuqin820222 in forum Qt Programming
    Replies: 2
    Last Post: 10th May 2013, 10:16
  3. problem with rowCount method
    By sergio486 in forum Qt Programming
    Replies: 2
    Last Post: 18th December 2010, 09:37
  4. Question on subclassing QSqlTableModel
    By Doug Broadwell in forum Qt Programming
    Replies: 4
    Last Post: 13th February 2010, 01:12
  5. QSqlTableModel and QSqlTableView question
    By waynew in forum Qt Programming
    Replies: 1
    Last Post: 14th December 2009, 01:06

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.