You are not logged in.

1

Friday, July 18th 2008, 1:01am

How to display partial data from a QSqlQueryModel in a QTableView?

I have a sql query that retrieves 100 records and I want to display 10 of those records at a time and provide "Next", "Previous" buttons to move across pags of records. Any pointers on how to achieve this? ?(

kaishin

Beginner

  • "kaishin" is male

Posts: 34

Location: Philippines

Occupation: Programmer

  • Send private message

2

Saturday, July 19th 2008, 8:24am

How to display partial data from a QSqlQueryModel in a QTableView?

hmm..

Limit your query to 10 first

when the next button click get 10 again but this time starting from the last number your tableview holding in this case 10+1

like: select * from table limit 11,10; //11 is where your query starts and 10 is the limit

if previous click subtract 10 to your last number.. and so on.. hope that help

3

Monday, July 21st 2008, 8:52pm

Updating the query for the next/previous pages by setting the limit and the offset indeed works.

However, I am trying to achieve some performance enhancement by not querying the database for every page. Instead, If I have 100 records on hand in the Model, I would like to display 10 at a time in the view. Not sure if this is achievable.

kaishin

Beginner

  • "kaishin" is male

Posts: 34

Location: Philippines

Occupation: Programmer

  • Send private message

4

Tuesday, July 22nd 2008, 3:41am

you can always use sqlrecord..

mveygman

Beginner

  • "mveygman" is male

Posts: 14

Location: Pocono Mountains

Occupation: Software Developer

  • Send private message

5

Saturday, July 26th 2008, 5:11pm

Updating the query for the next/previous pages by setting the limit and the offset indeed works.

However, I am trying to achieve some performance enhancement by not querying the database for every page. Instead, If I have 100 records on hand in the Model, I would like to display 10 at a time in the view. Not sure if this is achievable.
The simplest way would be to create a data structure representing the SQL Record coming back and then represent it as a vector or a dynamic array(you'd need to write this one) then just put the data you want to display into a Custom Model and present any way you like.
---

Regards,

Mikhail

6

Saturday, July 26th 2008, 5:47pm

look at QSortFilterProxyModel
Nicolas