[Qt-interest] QSqlite Table not showing all rows in app
Scott Aron Bloom
scott at onshorecs.com
Tue Feb 9 01:10:29 CET 2010
I haev found that the rowCount() does NOT contain all the rows as long
as the canFetchMore returns true. The model only loads 250 rows or so
into memory at a time.
One way to find all the rows...
QSqlQuery query = model->query();
query.last();
int numRows = query.at();
Scott
On Feb 8, 2010, at 3:54 PM, William Lugg wrote:
> I'm sure this would work, but it seems to defeat the whole MVC
> design pattern offered by Qt. It also doesn't solve the problem of
> the QDataWidgetMapper and/or the model running out of records
> prematurely at 250 records.
>
> Any ideas as to why the QSqlTableModel is under reporting the size
> of the table would be greatly appreciated.
>
> Thanks.
> ----
> Bill Lugg
> Milstar Software Support
> Peterson AFB, CO
> No Micro$oft products were used to create this email.
> God rules and if He needed a computer it would run Linux!
>
> On Saturday 06 February 2010 07:32:05 pm you wrote:
> > Since we are top posting, I don't use qt but my sql code would be:
> > 'SELECT count(*) FROM tablename' to get the number of rows...
> >
> > William Lugg wrote:
> > > Sorry, I should have included this info. I'm using a
> QSqlTableModel.
> > > Here is the line of code I use to report the total rows in the
> model:
> > >
> > > QString strRecordCount = " of "
> > > + QString::number(
> > > memberDataModel->rowCount() );
> > >
> > > I use a QDataWidgetMapper to map data to widgets. I use
> > > QDataWidgetMapper::toLast() and QDataWidgetMapper::toNext() to
> move
> > > forware in the code in the following way:
> > >
> > > // If we're not at the last record, move to the next record
> > > if ( memberDataMapper->currentIndex() < memberDataModel-
> >rowCount() )
> > > {
> > > memberDataMapper->toNext();
> > > setRecordCounter();
> > > }
> > >
> > > member_data_entry::setRecordCounter() looks like this:
> > > void member_data_entry::setRecordCounter()
> > > {
> > > ui->txtRecordNum->
> > > setText( QString::number( memberDataMapper->currentIndex() ) );
> > > return;
> > > }
> > >
> > > It returns 255 when I'm on the "last" record, which makes sense
> given
> > > zero- based counting, but doesn't make sense given that there
> are 3100
> > > records in the table.
> > >
> > > Any help would be greatly appreciated.
> > > ----
> > > Bill Lugg
> > > Milstar Software Support
> > > Peterson AFB, CO
> > > No Micro$oft products were used to create this email.
> > > God rules and if He needed a computer it would run Linux!
> > >
> > > On Saturday 06 February 2010 02:50:31 pm Robert Wood wrote:
> > >> William Lugg wrote:
> > >>> In the DB app I'm working on, when I query the model for the
> row count
> > >>> it claims it only contains 256 rows, though SQLite and a GUI
> browser I
> > >>> use to look at the DB both verify that there are actually
> upwards of
> > >>> 3100 rows in the table. What do I need to do in my code to get
> at the
> > >>> rest of the data?
> > >>>
> > >>> The problem is two fold - I need my record counter to report
> the total
> > >>> number of records and I need to be able to navigate to those
> records
> > >>> when the user wants to go there.
> > >>
> > >> Not sure how much sqllite differs from mysql, but how are you
> querying
> > >> the size of the database? Can we have a peek at the relevant
> line of
> > >> code please?
> > >>
> > >> This works for me in mysql in that it does return the number of
> rows in
> > >> the table:
> > >>
> > >> QSqlQuery query;
> > >> quint32 rows;
> > >> QString queryString;
> > >>
> > >> queryString = "SELECT * FROM tablename"
> > >> query.exec(queryString);
> > >> rows = query.size();
> > >> _______________________________________________
> > >> Qt-interest mailing list
> > >> Qt-interest at trolltech.com
> > >> http://lists.trolltech.com/mailman/listinfo/qt-interest
> > >
> > >
> ------------------------------------------------------------------------
> > >
> > > _______________________________________________
> > > Qt-interest mailing list
> > > Qt-interest at trolltech.com
> > > http://lists.trolltech.com/mailman/listinfo/qt-interest
>
> _______________________________________________
> Qt-interest mailing list
> Qt-interest at trolltech.com
> http://lists.trolltech.com/mailman/listinfo/qt-interest
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.qt-project.org/pipermail/qt-interest-old/attachments/20100208/e7ad89c0/attachment.html
More information about the Qt-interest-old
mailing list