Hello anyone,

I want to load my contact.txt in the function loadFile.
In my contact.txt i have seperated the items through tab.
When open the file for reading he display only in QTreeWidget 4 items
example:
Drabo Hardenberg Dhr. J. Tuik 0523-678905.

See code loadFile
Qt Code:
  1. void MainWindow::loadFile(const QString &fileName)
  2. {
  3. QFile file( fileName );
  4. if( !file.open(QFile::ReadOnly))
  5. return;
  6.  
  7. QTextStream in( &file);
  8. QString line;
  9. QTreeWidgetItem *item = new QTreeWidgetItem( contactView );
  10.  
  11. do {
  12.  
  13. line = in.readLine();
  14. if(!line.isEmpty())
  15. {
  16. QStringList contact = line.split('\t', QString::SkipEmptyParts);
  17. QStringList::Iterator it = contact.begin();
  18. if(it != contact.end())
  19. {
  20. item->setText(0, (*it));
  21. ++it;
  22. }
  23. if(it != contact.end())
  24. {
  25. item->setText(1, (*it));
  26. ++it;
  27. }
  28. if(it != contact.end())
  29. {
  30. item->setText(2, (*it));
  31. ++it;
  32. }
  33. if(it != contact.end())
  34. {
  35. item->setText(3, (*it));
  36. ++it;
  37. }
  38. }
  39.  
  40. }while(!line.isEmpty());
  41.  
  42. file.close();
  43.  
  44. }
To copy to clipboard, switch view to plain text mode 
Is there something missing in the code

Here is my code for the saveFile
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. ind ++;
  16. }
  17. file.close();
  18.  
  19. }
To copy to clipboard, switch view to plain text mode