The MVC architecture of Qt *View classes is brilliant except one little thing that is not pretty obvious from the beginning: how to find the QModelIndex instance corresponding to specific internal pointer. I wonder why, but I’ve searched the Internet pretty much until I’ve found the possible solutions on Qt developer FAQ page: “How can a QModelIndex be retrived from the model for an internal data item?”. There are three possible solutions. I’ve chosen the first and the simplest one: “Use unique identifiers” as far as it matched our requirements. The main idea of this option is that when you create the instance of a QModelIndex you pass the pointer to some internal data, but you should be sure that there will be no QModelIndex‘es pointing to the same data. So how to implement this approach?

Continue Reading »