tags:

views:

229

answers:

1

I am a Qt C++ programmer with some interest in Gtk+. I wonder how Gtk+ has implemented Model-View-Controller. In Qt they basically screwed it up, and have basically admitted that themselves. I can try to explain the flaws in Qt and for those who know Gtk+ perhaps you can answer whether Gtk+ has the same or worse problems:

Access to any node in say a tree model is based on a QModelIndex. So every node has a sort of unique ID. This creates a lot of complications. You have to create special methods for creating an index and for creating the index of the parent of a QModelIndex object. This can get quite involved. It is difficult to say create two Model objects and attach one of them as a node in the other model. The QModelIndex objects returned from one model are not compatible witth the other.

I think Cocoa made a much simpler model with NSOutlineView and NSOutlineViewDataSource. Qt's approach is more flexible but at the expense of being too difficult to use and get right. With Cocoa you don't use an index object but instead ask what the kid of object X is at index Y. And then you can ask about the value for a given table column Z and object X.

Qt does not have a particular easy to use way of invalidating a node in the tree, to make it reload. With Cocoa you can call reloadItem to make a particular object in tree and optionally its children get reloaded from Model.

This is part of my evaluation of how suited Gtk+ is. I am not trying to declare some kind of winner here ;-)

A: 

Assuming you're talking about trees mainly (GTK+ uses model-view-controller for other types of data as well, most notably text), the interface is called GtkTreeModel.

It uses GtkTreeIter as the low-level "pointer" into a model.

I don't think you can add one model as a child of another, in GTK+.

Invalidating a node is as easy as emitting the signal called row-changed, but typically you don't need to do that directly. For a simple tree of basic types, just setting a new value in a cell is enough to invalidate it.

unwind