I am trying to populate (and later hopefully edit) a QTreeView whose nodes are stored in a SQL table.

The structure is very simple and similar to a document:

Qt Code:
  1. Root
  2. |___Text
  3. |___Text
  4. |___Text
To copy to clipboard, switch view to plain text mode 

So the table is just:

ID: Int
Text: Varchar
ParentID: Int

I have read very many posts with similar questions and understand that the key is to use a QAbstractProxyModel between the QTreeView and the QSqlTableModel, in particular to look at implementing mapFromSource and mapToSource. I have also looked at the Interview demo which I think should be a good reference to link a flat structure to a tree.

Unfortunately being very new to Qt and still learning some of the advanced aspects of C++, I am struggling to fully understand what to do.

I would therefore really appreciate if someone has got some working code that I can try out and learn from - thanks