[Qt-qml] Extending with C++, basic QML list type question

bea.lam at nokia.com bea.lam at nokia.com
Tue Nov 22 04:35:34 CET 2011


Hi Harri,

On 22/11/2011, at 3:49 AM, ext Harri Pasanen wrote:
> 
> Chokes when it tries to index the guests property, spitting out a message:
> 'guests[1]' [undefined] is not an object.
> 
> Should this work, or what am I missing?


I can't reproduce this error with the built-in example - but, based on the error, I'm guessing that in your code, the guests list hasn't actually been populated somehow, so guests[1] isn't actually referencing a valid object.


> There is also some other underlying magic going on which is not explicit.
> 
> http://developer.qt.nokia.com/doc/qt-4.7/declarative-tutorials-extending-chapter5-listproperties-piechart-h.html#id-746a8ac4-61d2-42f8-82d6-2c72cd6c26a0
> 
> comes up with some static method called append_slice to populate the 
> list, but why does the birthday party example not feature it?

The BirthdayParty example just uses the simpler convenience constructor. Generally you would want to use the constructor that accepts the append-type function that will allow you to, for example, control the ownership of the object that has been appended to the list. In the PieChart example, the append_slice function also sets the parentItem of all append objects to be the PieChart itself; this wouldn't be possible if the list had been created with the convenience QDeclarativeListProperty constructor that doesn't accept an append function.


> Btw, are the example and tutorial projects show in the documentation 
> downloadable somewhere in compilable format?  Cutting and pasting from 
> the doc is not very tempting...
> Searching for the examples, at least the PieChart and BirthdayParty 
> don't seem to be part of QtSDK examples.


Yes, the paths to the examples are shown on the tutorial pages on http://developer.qt.nokia.com/doc/qt-4.7/declarative-tutorials-extending-chapter5-listproperties.html and http://developer.qt.nokia.com/doc/qt-4.7/qml-extending.html. That is, the PieChart example is located under examples/declarative/tutorials/extending/ and BirthdayParty is under examples/declarative/cppextensions/referenceexamples.


regards,

Bea



More information about the Qt-qml mailing list