Qt Quick Control’s TableView and C++ model using roles

Qt Quick Controls made big move forward in latest Qt releases. For example, in Qt 5.4 it takes native look on Android platform using styling option

Since it becomes more and more useful, its just waste of time to do not use it!

But its always there is some buts.

This time my stumbling-stone was TableView plus C++ data model











I’m not going to speechify a lot. Basically, standard scheme works, but my goal was to use roles as columns.In theory it was OK but every time I’ve met absence of data in my table. The only indicator that table works was increasing row counter

The problem was that roleNames() method of QAbstractItemModel class was not called. And the reason is that the method must be protected! For some reason this method in the Qt documentation as well as in tons of examples defined as public, and this is works in most cases but not for TableView!