On Mon, Dec 3, 2012 at 10:00 PM, Robert Voinea <rvoi...@gmail.com> wrote: > On Monday 03 December 2012 15:40:51 Mark wrote: > >> On Wed, Nov 28, 2012 at 4:16 AM, Mark <mark...@gmail.com> wrote: > >> > Op 26 nov. 2012 22:11 schreef "Mark" <mark...@gmail.com> het volgende: > >> >> Hi, > >> >> > >> >> I have a states array in QML that looks like this: > >> >> states: [ > >> >> > >> >> State { > >> >> > >> >> name: "icon" > >> >> > >> >> PropertyChanges { target: viewContainer; source: > >> >> "views/IconView.qml" } > >> >> > >> >> }, > >> >> State { > >> >> > >> >> name: "list" > >> >> > >> >> PropertyChanges { target: viewContainer; source: > >> >> "views/LView.qml" } > >> >> > >> >> }, > >> >> State { > >> >> > >> >> name: "tree" > >> >> > >> >> PropertyChanges { target: viewContainer; source: > >> >> "views/TreeView.qml" } > >> >> > >> >> } > >> >> > >> >> ] > >> >> > >> >> That works just fine, but i want to do it more dynamically. I want to > >> >> read the contents of the folder "views" and add a state entry for each > >> >> item that i fine. Reading the folder and getting the filename isn't an > >> >> issue, but i'm kinda puzzled how to build up a states array in > >> >> javascript. > >> >> > >> >> This is an pseudo code example: > >> >> buildstates.js > >> >> > >> >> var stateArray = ... construct the states based on based on the > >> >> content of a folder ... > >> >> > >> >> main.qml > >> >> import "buildstates.js" as BuildStates > >> >> > >> >> Item{ > >> >> > >> >> width: 800 > >> >> height: 600 > >> >> states: BuildStates.stateArray > >> >> > >> >> } > >> >> > >> >> I want to do the same for transitions. > >> >> But how do i do the JavaScript part? Or is there another way to build > >> >> up a dynamic states/transitions array? Or is there a C++ way for this? > >> >> > >> >> Cheers, > >> >> Mark > >> > > >> > Anyone..? > >> > >> 2nd try. Anyone? > >> _______________________________________________ > >> Interest mailing list > >> Interest@qt-project.org > >> http://lists.qt-project.org/mailman/listinfo/interest > > > > > > Try Component.create() > > > > I have not tried this approach, but for dynamic creation of QML elements > that is the way. > > > > In C++ land... > > > > You'd have to use QDeclarativeComponent::create to generate > states/transitions and then assign then to your QML Item... but first you'd > have to identify the item... a way to do that is setting objectName from > within QML and then use QObject introspection to find the item. > > > > Also, you have to be careful about ownership (who "owns" the newly created > components?) > > > > Again...I haven't tried either of these methods. > > > > -- > > Robert Voinea > > IT Specialist > > +4 0740 467 262 > > > > Don't take life too seriously. You'll never get out of it alive. > > (Elbert Hubbard)
Hi Robert, Thank you for the reply. I'm certainly going to test that out :) If i have any findings they will be posted in here. Cheers, Mark _______________________________________________ Interest mailing list Interest@qt-project.org http://lists.qt-project.org/mailman/listinfo/interest