On Tue, Aug 18, 2015 at 4:25 AM, Grace Karanja <[email protected]>
wrote:

> Hi Tomaz,
>
> I am a bit stuck here:
>
> Check my code here:
> https://github.com/gracie89/subsurface/tree/devel/qt-mobile
>
> When the user clicks on Add Dive, I want to add a new dive to the model.
> This is working. But how do I tell QML to go the the new empty dive?
>
> This file:
> https://github.com/gracie89/subsurface/blob/devel/qt-models/divelistmodel.cpp
>
> on line
> 341
>
> Is where I am adding the dive
> struct dive *d;d = alloc_dive();add_single_dive(get_divenr(d), d);addDive
> (d);
>
>
> This works ok, but now I want to tell the model to go to the last item :(
>

Grace,

a Model, in Qt, doesn't have the notion of 'current', so the thing you
should look at is "how can I manage to get the ListView to select the last
item added on the model"

the ListView has a 'count' property ( and this will work for all
properties, so you already know how to deal with anything after this )
each property has a 'on___changed', so: onCountChanged will work, also the
current selected thing on ListView is set by the currentIndex, that is just
a int, so you just need to pass your correct index when count changes:

ListView {

...
...
    onCountChanged: {
          currentIndex = count-1;
    }
}




> --
> --
> Grace K
>
_______________________________________________
subsurface mailing list
[email protected]
http://lists.subsurface-divelog.org/cgi-bin/mailman/listinfo/subsurface

Reply via email to