<div dir="ltr"><br><div class="gmail_extra"><br><div class="gmail_quote">On Tue, Aug 18, 2015 at 9:51 PM, Tomaz Canabrava <span dir="ltr"><<a href="mailto:tcanabrava@kde.org" target="_blank">tcanabrava@kde.org</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><br><div class="gmail_extra"><br><div class="gmail_quote"><span class="">On Tue, Aug 18, 2015 at 4:25 AM, Grace Karanja <span dir="ltr"><<a href="mailto:gracie.karanja89@gmail.com" target="_blank">gracie.karanja89@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">Hi Tomaz,<div><br></div><div>I am a bit stuck here:</div><div><br></div><div>Check my code here: <a href="https://github.com/gracie89/subsurface/tree/devel/qt-mobile" target="_blank">https://github.com/gracie89/subsurface/tree/devel/qt-mobile</a></div><div><br></div><div>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?</div><div><br></div><div>This file: <a href="https://github.com/gracie89/subsurface/blob/devel/qt-models/divelistmodel.cpp" target="_blank">https://github.com/gracie89/subsurface/blob/devel/qt-models/divelistmodel.cpp</a></div><div><br></div><div>on line </div><div>341</div><div><br></div><div>Is where I am adding the dive</div><div><table style="border-collapse:collapse;border-spacing:0px;color:rgb(51,51,51);font-family:Helvetica,arial,nimbussansl,liberationsans,freesans,clean,sans-serif,'Segoe UI Emoji','Segoe UI Symbol';font-size:13px;line-height:18.2000007629395px"><tbody><tr><td style="padding:0px 10px;vertical-align:top;font-family:Consolas,'Liberation Mono',Menlo,Courier,monospace;font-size:12px;white-space:pre-wrap;overflow:visible;word-wrap:normal"><span style="color:rgb(167,29,93)">struct</span> <span style="color:rgb(121,93,163)">dive</span> *d;</td></tr><tr><td style="padding:0px 10px;width:50px;min-width:50px;white-space:nowrap;font-family:Consolas,'Liberation Mono',Menlo,Courier,monospace;font-size:12px;line-height:18px;color:rgba(0,0,0,0.298039);vertical-align:top;text-align:right;border-style:solid;border-color:rgb(238,238,238);border-width:0px 1px 0px 0px"></td><td style="padding:0px 10px;vertical-align:top;font-family:Consolas,'Liberation Mono',Menlo,Courier,monospace;font-size:12px;white-space:pre-wrap;overflow:visible;word-wrap:normal">d = <span style="color:rgb(0,134,179)">alloc_dive</span>();</td></tr><tr><td style="padding:0px 10px;width:50px;min-width:50px;white-space:nowrap;font-family:Consolas,'Liberation Mono',Menlo,Courier,monospace;font-size:12px;line-height:18px;color:rgba(0,0,0,0.298039);vertical-align:top;text-align:right;border-style:solid;border-color:rgb(238,238,238);border-width:0px 1px 0px 0px"></td><td style="padding:0px 10px;vertical-align:top;font-family:Consolas,'Liberation Mono',Menlo,Courier,monospace;font-size:12px;white-space:pre-wrap;overflow:visible;word-wrap:normal"><span style="color:rgb(0,134,179)">add_single_dive</span>(<span style="color:rgb(0,134,179)">get_divenr</span>(d), d);</td></tr><tr><td style="padding:0px 10px;width:50px;min-width:50px;white-space:nowrap;font-family:Consolas,'Liberation Mono',Menlo,Courier,monospace;font-size:12px;line-height:18px;color:rgba(0,0,0,0.298039);vertical-align:top;text-align:right;border-style:solid;border-color:rgb(238,238,238);border-width:0px 1px 0px 0px"></td><td style="padding:0px 10px;vertical-align:top;font-family:Consolas,'Liberation Mono',Menlo,Courier,monospace;font-size:12px;white-space:pre-wrap;overflow:visible;word-wrap:normal"><span style="color:rgb(0,134,179)">addDive</span>(d);</td></tr></tbody></table></div><div><br></div><div><br clear="all"><div>This works ok, but now I want to tell the model to go to the last item :(</div></div></div></blockquote><div><br></div></span><div>Grace,<br><br></div><div>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"<br><br></div><div>the ListView has a 'count' property ( and this will work for all properties, so you already know how to deal with anything after this )<br></div><div>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:<br><br></div><div>ListView {<br><br>...<br>...<br>    onCountChanged: {<br>          currentIndex = count-1;<br>    }<br>}</div></div></div></div></blockquote><div><br></div><div>Thanks, Tomaz.</div><div><br></div><div>This has helped!</div><div><br></div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div class="gmail_extra"><div class="gmail_quote"><div><span class="HOEnZb"><font color="#888888"><br><br><br></font></span></div><span class="HOEnZb"><font color="#888888"><div> <br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div><span><font color="#888888">-- <br><div><div dir="ltr">--<div>Grace K</div></div></div>
</font></span></div></div>
</blockquote></font></span></div><br></div></div>
</blockquote></div><br><br clear="all"><div><br></div>-- <br><div class="gmail_signature"><div dir="ltr">--<div>Grace K</div></div></div>
</div></div>