Usually one implements the following structure:

Qt Code:
  1. struct Item {
  2. Item *parent;
  3. QList<Item*> children;
  4. };
To copy to clipboard, switch view to plain text mode 

and then parent() becomes something like:
Qt Code:
  1. QModelIndex Model::parent(const QModelIndex &index) const {
  2. if(!index.isValid()) return QModelIndex();
  3. Item *item = static_cast<Item*>(index.internalPointer());
  4. Item *parent = item->parent;
  5. if(parent == m_rootItem ) { return QModelIndex(); } // I'm top level
  6. Item *grandParent = parent->parent;
  7. int row = grandParent->children.indexOf(parent); // find out the row number of the parent
  8. return createIndex(row, 0, parent);
  9. };
To copy to clipboard, switch view to plain text mode 

This makes sense for trees while it doesn't have to make sense for arbitrary graphs (there is no concept of a root item). And I understood the OP's question correctly and I gave a good answer (to make the tree model a subset of an external graph representation) for it.