Try something like this:

Qt Code:
  1. void MainWindow::saveFile(const QString &fileName)
  2. {
  3.  
  4. QFile file( fileName );
  5. if ( !file.open(QFile::WriteOnly))
  6. return;
  7.  
  8. QTextStream out( &file );
  9.  
  10. int ind = 0;
  11. while(QTreeWidgetItem *item = contactView->topLevelItem(ind)) {
  12. for ( unsigned int i = 0; i < 4; i++ )
  13. out << item->text(i) << '\t';
  14. out << '\n';
  15.  
  16. ind ++;
  17. }
  18. file.close();
  19.  
  20. }
To copy to clipboard, switch view to plain text mode