title: Order of QObject children (strategy question)
body: <p>For one of my projects I have a tree of QObject derived objects, which utilize QObject's parent/child functionality to build the tree.</p>
  
  <p>This is very useful, since I make use of signals and slots, use Qt's guarded pointers and expect parent objects to delete children when they are deleted.</p>
  
  <p>So far so good. Unfortunately now my project requires me to manage/change the order of children. QObject does not provide any means of changing the order of its children (exception: QWidget's raise() function - but that's useless in this case). <em>So now I'm looking for a strategy of controlling the order of children.</em> I had a few ideas, but I'm not sure about their pros &amp; cons:</p>
  
  <p><br><br></p>
  
  <h2><strong>Option A:</strong> Custom sort index member variable</h2>
  
  <p>Use a <code>int m_orderIndex</code> member variable as a sort key and provide a <code>sortedChildren()</code> method which returns a list of QObjects sorted by this key.</p>
  
  <ul>
  <li>Easy to implement into existing object structure.</li>
  <li>Problematic when <code>QObject::children()</code> method is overriden - will lead to problems during loops when items' order is changed, also is more expensive than default implementation.</li>
  <li>Should fall back to QObject object order if all sort keys are equal or 0/default.</li>
  </ul>
  
  <hr>
  
  <h2><strong>Option B:</strong> Redundant list of children</h2>
  
  <p>Maintain a redundant list of children in a <code>QList</code>, and add children to it when they are created and destroyed.</p>
  
  <ul>
  <li>Requires expensive tracking of added/deleted objects. This basically leads to a second child/parent tracking and lot of signals/slots. QObject does all of this internally already, so it might not be a good idea to do it again. Also feels like a lot of bloat is added for a simple thing like changing the order of children.</li>
  <li>Good flexibility, since a QList of children can be modified as needed.</li>
  <li>Allows a child to be in the QList more than one time, or not at all (even though it might be still a child of the QObject)</li>
  </ul>
  
  <hr>
  
  <h2>Option C: ...?</h2>
  
  <p><em>Any ideas or feedback, especially from people who already solved this in their own projects, is highly appreciated. Happy new year!</em></p>