Connecting existing C++ code to QML
I am trying to put a QML front end to an existing application. The new user interface will consist of about 50 or so screens. Each screen will typically contain select-able strings representing the back end C++ objects. (Think of these pages as containing file listings).
Thanks to other users in the QT forums I am now able to make a QT application link to my existing code libraries but now I need to fill in the missing gaps on how to bridge the gap between QML and the non QT based C++ back end library code. I'm a little lost as to what to do next. I went through the following to get up to speed on the model view but this does not quite bridge the missing QML to C++ gap. Any help with a similar extension of a QAbstractListModel and exposing it to QML would be greatly appreciated. Thanks in advance.
The link you posted uses C++ for both the model and the view.
See this page for info on integrating C++ models with QML views: http://qt-project.org/doc/qt-5.1/qtquick/qtquick-modelviewsdata-cppmodels.html
Models aren't the only way to go though. See this page for other integration techniques: http://qt-project.org/doc/qt-5.1/qtqml/qtqml-cppintegration-topic.html (the best choice depends on your existing data structure)
Thanks for the useful docs above, I read this and it looks like the kind of thing I need, but for some reason I cannot get QML to display anything in the C++ code. Most of my C++ classes that I am trying to use have getters that return std::vector<T> or std::map<T> of objects. I simply want to display these in a ListView using a custom model. I never would have thought something so seemingly simple would turn out to be so difficult. I have spent almost a week pouring over examples and failing to get things to build.
I'm thinking that should probably try to wrap the QAbstractListModel derived models in a reusable Plugin and import/use these from the QML user interface pages. However, for some strange reason, I cannot get most of the default examples to run - in particular the Clock plugin example from \Qt\Qt5.1.1\5.1.1\msvc2012_64_opengl\examples\qml\plugins pops up what I think is the qmlscene application prompting me for a QML file. When I point it to the the QML file for the clock it is basically a static clock image without hands. Please help!
I'm not sure that plugins are the way to go. It would add unnecessary complexity to your program.
To start of, try getting a QML view to display a simple QStandardItemModel (this is derived from QAbstractItemModel, but is much easier to work with than QAbstractItemModel).
Post your code and error messages if you'd like further assistance.