Greetings.
I have a MySQL table with the following structure:
Qt Code:
  1. id | name | parent_node
To copy to clipboard, switch view to plain text mode 
`id` is int primary key, auto increment enabled.
`name` is a text string
`parent_node` is an int and holds the id of the previous node.

I query the database and populate a QList<QTreeWidgetItem*> item_list;
Qt Code:
  1. while (query->next())
  2. {
  3. tree->setText(0, query->value(1).toString());
  4. tree->setText(1, query->value(0).toString());
  5. tree->setText(2, query->value(2).toString());
  6. item_list.append(tree);
  7. }
To copy to clipboard, switch view to plain text mode 

All is well, but I wonder if my iteration over the list and constructing the tree is optimal. The table contains 10 rows, but in the future it's gonna hold at least 1000 rows and I wonder if the program is going to behave nice, since the tree is constructed on startup (in the main class' constructor).

Here's my iterations:
Qt Code:
  1. for (int j=0;j<item_list.count();j++)
  2. {
  3. QTreeWidgetItem* current = item_list[j];
  4. for (int i=0; i<item_list.count();i++)
  5. {
  6. qDebug() << "Current item: " << current->text(0);
  7. if (current->text(2).toInt() == item_list.at(i)->text(1).toInt())
  8. {
  9. item_list.at(i)->addChild(current);
  10. }
  11. else if (current->text(2).toInt()==0)
  12. {
  13. ui->treeWidget->addTopLevelItem(item_list.first());
  14. }
  15. }
  16. }
  17. }
To copy to clipboard, switch view to plain text mode 
Thanks for your help!