It appears if I display something inside the implementation of hasChildren on a QAbstractItemModel I get a segfault.
This is easily reproducible with the simpletreemodel example included in the source tarball.
Simply add the following method to treemodel.cpp (and corresponding method to the header as well).
You can click through the first round of messages. After that when you mouse over one of the tree items it will give you another prompt. After clicking it you'll segfault.

Qt Code:
  1. #include <string>
  2. #include <sstream>
  3.  
  4. // ...
  5.  
  6. bool TreeModel::hasChildren(const QModelIndex &parent) const
  7. {
  8. std::ostringstream oss;
  9. if (!parent.isValid()) {
  10. oss << "hasChildren root" << std::endl;
  11. } else {
  12. oss << "hasChildren (" << parent.row() << "," << parent.column() << ")" << std::endl;
  13. }
  14. oss << QAbstractItemModel::hasChildren(parent) << std::endl;
  15.  
  16. QMessageBox::information((QWidget*)QAbstractItemModel::parent(), "TITLE", QString::fromStdString(oss.str()));
  17. return QAbstractItemModel::hasChildren(parent);
  18.  
  19. }
To copy to clipboard, switch view to plain text mode 

Since I'm sure it will be asked, let me explain why I'm doing this.
I have an application which connects to a server but can also work off-line.
While connected a user can drag an item from the server to their local cache.
This does a shallow copy.
If the user then closes and re-opens the application they will see their local copy of that top level item and 1 level of items under it.
Expanding nodes any further than what the client has cached locally will cause a login dialog to appear to log into the server.

What should I do?
I'm open to suggestions.