On Tue, 16 Nov 2010 22:50:05 Kellomaki Pertti (Nokia-MS/Tampere) wrote: > Is it possible to have executable code as part of a model element? In a > hypothetical Scheme based QML I could create a list model that contains > <string, procedure> pairs, and then in a list view a delegate could > simply call the procedure: > > (define file-menu > (list > (list "Save" > (lambda () (save-file))) ; executable code > (list "Quit" > (lambda () (quit)))) > > Does QML allow something like this, or is there some other convenient > way to glue together e.g. labels and actions?
While I'm going to withhold judgment for now on whether what I'm suggesting is a good idea, you can just have strings of javascript in the model and execute them with eval(). e.g ListModel{ ListElement{ name: "Save" action: "saveFile()" } ListElement{ name: "Quit" action: "Qt.quit()" } } and inside the delegate somewhere: eval(action); Not quite the same as your example, because the code as a string will be evaluated in the context of wherever eval was called but if save-file() was still visible in that context then it would work. -- Alan Alpert Software Engineer Nokia, Qt Development Frameworks _______________________________________________ Qt-qml mailing list Qt-qml@trolltech.com http://lists.trolltech.com/mailman/listinfo/qt-qml