I recently spent some time working out how to use a QDataStream with a QTreeWidget in PyQt.  I never found specific examples for doing exactly this, and pyqt documentation for QDataStream seems to be pretty scarce in general.  So I thought I'd post a question here as a breadcrumb trail in case someone else down the line needs a hint.  I'll wait a bit in case someone would like to jump in and take a shot at it, and I'll post back in a bit with my own efforts.
The question is: In PyQt, how can I use a QDataStream to save QTreeWidgetItems to a file as native QT objects, and then read the file back to restore the tree structure exactly as it was saved?
Eric
The QTreeWidget is a red herring. What you are saving is a generic QAbstractItemModel (treeWidget->model()) - after all, a QTreeWidget is a view, and has a built-in model. Now, those model's items are simply QVariants, and those are simply Python types, but also fully supported by QDataStream::operator<<. All you need is to choose a tree traversal (depth-first, breadth-first, or something else), and dump the items and their depth in the tree to the stream. When you read the stream, that's sufficient information to reconstruct the tree.
PyQt: Saving native QTreeWidgets using QDataStream