Results 1 to 5 of 5

Thread: QSqlTableModel::select()

  1. #1
    Join Date
    Apr 2009
    Posts
    17
    Thanks
    7
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Question QSqlTableModel::select()

    Hi,
    Im writing a small program that uses SQlite database. I ran into a small problem when i select rows from the table.

    Qt Code:
    1. model.setTable("vlad");
    2. //model.setFilter("id >=500");
    3. model.select();
    4. int rows = model.rowCount(); //rows = 256
    To copy to clipboard, switch view to plain text mode 

    The problem is that it will select first 256 rows from the table regardless if I use the filter or not. My database table has at least 4000 rows, and I need a method to select ALL rows.

    Thanks you

  2. #2
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,004 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: QSqlTableModel::select()

    Hi, see QSqlQueryModel::fetchMore(). Qt is only loading a piece of data and will reload if necessary.

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

    vladozar (29th April 2009)

  4. #3
    Join Date
    Jan 2006
    Location
    Napoli, Italy
    Posts
    621
    Thanks
    5
    Thanked 86 Times in 81 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QSqlTableModel::select()

    After a select the model doesn't load all rows from Database.

    With SQLITE the QuerySize isn't available then you can use the code
    Qt Code:
    1. while (model.canFetchMore())
    2. {
    3. model.fetchMore();
    4. }
    To copy to clipboard, switch view to plain text mode 
    A camel can go 14 days without drink,
    I can't!!!

  5. The following 2 users say thank you to mcosta for this useful post:

    vladozar (29th April 2009), waynew (10th November 2011)

  6. #4
    Join Date
    Apr 2009
    Posts
    17
    Thanks
    7
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Talking Re: QSqlTableModel::select()

    Thank you Lykurg and mcosta for your advice. your help really works.

    Here is my updated code and it works, Thanks A lot
    Qt Code:
    1. model.setTable("vlad");
    2. model.select();
    3. while (model.canFetchMore())
    4. {
    5. model.fetchMore();
    6. }
    7. int rows = model.rowCount();
    8. QString outext = "row Count:" + QString::number(rows);
    9. qDebug() << outext;
    To copy to clipboard, switch view to plain text mode 

  7. The following user says thank you to vladozar for this useful post:

    shobogenzo (6th October 2010)

  8. #5
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,004 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: QSqlTableModel::select()

    An advice: don't use fetchmore if not really necessary. If you want the rowcount use a simple QSqlQuery. Don't know your concept or what you want to achieve but fetchmore is needed in only a few cases.

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.