Hello friends,

I try a little routine to fill up a tableview from a textfile.

Qt Code:
  1. //**************************************************************************
  2. void Window::openFileInTable(const QModelIndex & index )
  3. //**************************************************************************
  4. {
  5.  
  6. int digits[6];
  7. int iSegCount(0);
  8. int iCopyFLines(0);
  9. QString selectedFile;
  10. if ( index.isValid())
  11. {
  12. selectedFile = model->filePath( index );
  13. selectedFile.replace(QString("/"),QString("\\"));
  14. bodyEdit->clear();
  15. bodyEdit->append(selectedFile);
  16.  
  17. QFile file(selectedFile);
  18. if (!file.open(QIODevice::ReadOnly | QIODevice::Text))
  19. return;
  20. int fileLines(1);
  21. QTextStream InputDataFile(&file);
  22. while (!InputDataFile.atEnd()) {
  23. InputDataFile.readLine();
  24. fileLines++;
  25. }
  26. file.close();
  27. QTextStream InputDataFile(&file);
  28. if (!file.open(QIODevice::ReadOnly | QIODevice::Text))
  29. return;
  30. QStringList buffer_list;
  31. QString Delimiter(";");
  32. tableModel = new QStandardItemModel;
  33. tableModel->setRowCount(0) ;
  34. int Max_Number_of_Columns(36);
  35. int Max_Number_of_Lines(0);
  36. tableModel->setColumnCount(Max_Number_of_Columns + 3) ;
  37. progressDialog->setMaximum(fileLines);
  38. for(iSegCount=0;iSegCount<6;iSegCount++){digits[iSegCount]=0;}
  39. QString buf;
  40. while (!InputDataFile.atEnd())
  41. {
  42. buf = InputDataFile.readLine();
  43. buffer_list = buf.split(Delimiter);
  44.  
  45. for (int column = 0; column <= Max_Number_of_Columns; column ++)
  46. {
  47. QStandardItem * item = new QStandardItem(buffer_list[column]);
  48. tableModel->setItem(Max_Number_of_Lines, column, item) ;
  49. }
  50. Max_Number_of_Lines++;
  51. progressDialog->setLabelText(tr("Transfer %1...").arg(selectedFile));
  52. progressDialog->setWindowModality(Qt::WindowModal);
  53. progressDialog->setValue(Max_Number_of_Lines);
  54.  
  55. }
  56. iCopyFLines=Max_Number_of_Lines;
  57. iSegCount = 0;
  58. do {
  59. digits[iSegCount++] = iCopyFLines % 10;
  60. } while ((iCopyFLines /= 10) > 0);
  61. progressCountEiner->setNumber(digits[0]);
  62. progressCountZehner->setNumber(digits[1]);
  63. progressCountHunderter->setNumber(digits[2]);
  64. progressCountTausender->setNumber(digits[3]);
  65. progressCountZehnTausender->setNumber(digits[4]);
  66. progressCountHundertTausender->setNumber(digits[5]);
  67.  
  68. progressDialog->setValue(fileLines);
  69. trackView->setAutoFillBackground(true);
  70. trackView->setAlternatingRowColors(true);
  71. trackView->resizeColumnsToContents();
  72. trackView->setModel(tableModel);
  73. trackView->show() ;
  74. }
  75.  
  76. }
To copy to clipboard, switch view to plain text mode 


What I detect is that the bigger the textfile is the greater the memory consumption is.

The problem I think is the for loop:
Qt Code:
  1. for (int column = 0; column <= Max_Number_of_Columns; column ++)
  2. {
  3. QStandardItem * item = new QStandardItem(buffer_list[column]);
  4. tableModel->setItem(Max_Number_of_Lines, column, item) ;
  5. }
To copy to clipboard, switch view to plain text mode 

Have somebody a tip to filling up my tableview with better performance or lower memory consumption ..???