Not much of a functional difference between recursive and iterative approaches. Where iterative use some sort of storage variable and increment to keep track of its progress, recursion uses the call stack to keep track of its progress. Some solutions to some problems are solved simpler recursively than iteratively. As for my purposes, I just want something readable since recursion is very short, terse code that is difficult to trace at times. Iterative approaches are clearer to the eye.

Theoretically, for every recursive solution to a problem, there is a recursive one to match. The matched pair may have great discrepencies in how they use memory and their codespace.

I tried to modify your code so that I would first be able to change the color of the top level items. This is what I tried:

Qt Code:
  1. // Iterate through patients...
  2. for(QModelIndex Patient_Node = model()->index(0,0);
  3. Patient_Node.isValid();
  4. Patient_Node = model()->index(Patient_Node.row()+1,0) )
  5. {
  6. model()->setData(Patient_Node, Qt::red, Qt::TextColorRole);
  7. }
To copy to clipboard, switch view to plain text mode 

When executing, I get:

ASSERT failure in QList<T>::at: "index out of range", file /export/data/jsalik/local/Qt-4.1.1/include/QtCore/qlist.h, line 361


indicating that something out of range was being indexed.