PDA

View Full Version : Limitation when adding more than 256 items to a model



darkadept
25th May 2006, 07:12
I have a simple contact database application that stores names and phone numbers etc.

I've subclassed my own model which has lots of logic and uses a QSqlTableModel for actual storage (for reasons which i won't go into here).

My setup for developing is Linux + Qt4 + GCC + MySql.
My testing setup is Windows 2k + Qt4 + MinGW + MS-Sql Server (via odbc)

On linux I have no problems adding new items to the model.
On the windows setup I can only add 256 item and then it stops working.

Is this a modelindex/persistantmodelindex problem? a limitation of window qt4? a limitiation of mingw? something else entirely?

zlatko
25th May 2006, 10:22
a limitation of window qt4? a limitiation of mingw?

Yes it can be cause of suspicion :rolleyes:

wysota
25th May 2006, 10:55
What does "stop working" mean? Can you add those entries manually using the sql calls? Maybe the database is set up incorrectly?

darkadept
25th May 2006, 15:27
Sorry for the incoherent post. I was debugging this thing far too late into the night.

I can still insert new items into the model and that successfully saves to the database, so i'm not suspecting the DB anymore.

I am not using a Qt view to display my model but had to create my own "view" class to do it. I had tried subclassing the QAbstractItemView class but could never get that to work properly (i'll save that for a different post). So in my "view" class i have to keep track of which ModelIndex i'm currently on, etc. (My view only displays one item in the model at a time). The user can move forward and back through the items in the model.

What's odd is that it works fine under Linux/Mysql but doesn't work under Windows/MSSQL. My first thought I had when I heard it wasn't letting the user move past #256 was an issue with typing. I thought that maybe the "int" with linux/gcc has a different bit-size then the "int" on windows/mingw.

I've got more debugging to do, i know, but i was wondering if anyone else has run into this kind of problem when porting from linux to windows.

wysota
25th May 2006, 15:37
The models themselves don't introduce limitations on both Linux and Windows. The problem has to lie in your code somewhere between the model and the user interaction. Can you move through the model manually? For example try this:
qDebug(qPrintable(model->data(300,0).toString()));

darkadept
25th May 2006, 16:26
And you're right!
After much qDebug()ing I got it. And, of course, it's something really stupid.

The problem was with my reimplemented rowCount function. I was just returning my QSqlTableModel's rowcount. The problem there is that the QMYSQL driver supports the QSqlDriver::QuerySize feature while QODBC driver doesn't. That means in windows I was stuck with the default 256-record cache.

The workaround i have now is to run a "SELECT COUNT(id) FROM table" and return that value in my model's rowCount method. This is far from efficient and run's sluggishly.

I guess I could maintain a counter and increase/decrease as I add and remove records. Or is there a better way to do this?

(THANKS so much for the help!)