[Development] Access lazy Models from within QML

Dominik Holland dominik.holland at pelagicore.com
Mon Mar 4 10:36:22 CET 2013


Hi all,

i'm currently in a project where i try to access a lazy C++ model from 
within QML.

The basics are working well but when it comes to setting the 
currentIndex it becomes a bit odd.

If i implemented everything well the lazy model always reports the 
element count it currently has loaded by rowCount(). If the List comes 
to the end, it will call canFetchMore() and if true also fetchMore() to 
get more elements.

But when somebody tries to set the currentIndex to something which is 
currently not loaded into the lazy model, the data will not be loaded 
automatically and the Highlight set accordingly.

I looked it up at the source code and the code of the QML Views are 
always checking the currentIndex to be smaller than the model's count. 
Because of this the View rejects the currentIndex instead of trying to 
load the full content of the model to determine whether the index is 
really out of bound.

Some my question is, is this a Bug in QtDeclarative ? If so what do you 
think should be the right behavior ? Loading all the content just to 
check whether the index is in bound seems to me a bit too performance 
consuming.

Do you think a other implementation of lazy models for QML should be 
done than this should be documented somewhere.

Best Regards
  Dominik



More information about the Development mailing list