title: PySide: QTreeView to nested dictionary
body: <p>I need help to build a hierarchical nested dict from a QTreeView structure to get something like this:</p>
  
  <pre><code> {"A": {"B": {"H": {}, "I": {"M": {}, "N": {}}}, "D": {}, "E": {}, "F": {}, "G": {"L": {}}, "C": {"J": {}, "K": {}}}}
  
  {
      "A": {
          "B": {
              "H": {}, 
              "I": {
                  "M": {}, 
                  "N": {}
               }
          }, 
          "D": {}, 
          "E": {}, 
          "F": {}, 
          "G": {
              "L": {}
          }, 
          "C": {
              "J": {}, 
              "K": {}
          }
      }
  }
  </code></pre>
  
  <p>I am not using columns in this case and the QTreeView represents a directory structure (i actually extracted it from a dict like tho one above and just want to recreate the dict after modifying the Tree)</p>
  
  <p>I already have some thing like this:</p>
  
  <pre><code>def to_dict(self, _structure={}, _parent=''):
      sublist[self.name()] = self._children
  
      for child in self._children:
          _structure[self.name()] = sublist
          child.to_dict(_structure, self.name())
  </code></pre>
  
  <p>Obviously self._children is a list so it wont work</p>
  
  <p>EDIT: I think i might need something like this:</p>
  
  <pre><code>def to_dict(self, _structure={}, _parent=''):
  
      sublist = {self.name(): {}}
  
      for child in self._children:
          if _parent == '':
              _structure = sublist
          else:
              _structure[_parent].update(sublist)
          child.to_dict(_structure, self.name())
  
      return _structure
  </code></pre>
  
  <p>The Problem here is...i need to find the _parent key in the _structure dictionary and as far as i understand it will always be in the lowest level of the dict...do i really need to search the whole _structure dict averytime a want to add a new subdict to the given _parent or is there a better solution to my problem?</p>