I think, you can write it like:
[..]
for(int h = 0; h < ui->treeWidget->topLevelItemCount(); h++)
{
QDomElement file = document.createElement("File");
QTreeWidgetItem *item = ui->treeWidget->topLevelItem(h);
file.setAttribute("ID", item->text(0)); //1
file.setAttribute("Path", item->text(1)); //2
playlist.appendChild(file);
}