My first medium-sized-ish QML application was one very similar to what you're proposing, and the approach worked very well. Two comments... You'll want to use a C++ model to back your UI for your network resources; that way you can update the model from C++ and the UI will automatically redraw. You'll want to create a subclass of QAbstractListModel, or use a subclass like QStandardItemModel (which is fine for general lightweight work), and jam that puppy into your QML context (http://doc.qt.nokia.com/4.7-snapshot/qtbinding.html#embedding-c-objects-into-qml-components, http://www.lothlorien.com/kf6gpe/?p=160). Using a model is preferable to using QList<T>, because as the model changes, it signals to the UI to change automatically. In my case, I created a QStandardItemModel subclass that was a back-end listening to QtDBus notifications, so signals on the DBus propagated to, and seamlessly updated, my QML interface. It worked very well.
You can wire stuff back to your C++ app from your QML's ListView delegate by using a MouseArea that dispatches to a Q_INVOKABLE property on an object shared between C++ and QML; see the previous links as well. I found it pretty handy (if a bit sloppy) to make my application controller class available in QML, and then just put some Q_INVOKABLE methods on it so that the QML could trigger state changes in the app controller logic. So your app controller could have a Q_INVOKABLE method "doSomething" that the MouseArea onClicked handler invokes, passing whatever info from the current item of the model is necessary to your application logic. Hope that helps! Cheers, R. -----Original Message----- From: [email protected] [mailto:[email protected]] On Behalf Of ext Christian Benjamin Ries Sent: Wednesday, September 07, 2011 6:17 AM To: [email protected] Subject: [Qt-qml] Possibility of an implementation approach? Hello all together! I rechecherd a little bit and checked out the possibilities of QML, everything sounds nice and easy to apply. I already checked how I can add an QML declarative object to a GraphicScene and how I could move them around. Now I stuck, I've no idea if I can use QML efficiently in my project. Here a small description of my task: - I have to create a graphical view of some elements, e.g. a host with included childs like network-interface cards. - These hosts could have descriptions for file-shares, and I like to add them to the host on the fly by a C++-programm, and the view sould be repaint in the QGraphicalView. - I have seen, that I can add a list<T> in QML, could I add elements to this list by C++? If yes, could you give me an example or a link to one example? - Furthermore, when I click a one MouseArea I like to use this click-Signal in my C++-programm, but there is no available example on the Qt's-website, right? I really like to use QML, because it could safe a lot of time! Because their is no need to create items of all elements with a QGraphicsItem based spezialization, and the calculation of all positions and so on... I really checked the web and Qt's documentation, but the available examples covers not really an example how I could do the mentioned implementation things. Suggestions will be welcome(!) All the best, Christian _______________________________________________ Qt-qml mailing list [email protected] http://lists.qt.nokia.com/mailman/listinfo/qt-qml _______________________________________________ Qt-qml mailing list [email protected] http://lists.qt.nokia.com/mailman/listinfo/qt-qml
