Hey guys!

I have data stored in vectors that I would like to show in a QTextEdit. What I do now is I create a QTextDocument and a QTextCursor and I append all data as QStrings into that Document like this (altered some things so you can try to compile if needed):

Qt Code:
  1. QTextDocument* parseDoc(std::vector<double>& time, std::vector<std::array<double,3>>& pos, std::vector<std::array<double,3>>& pos){
  2. parsedDocument = new QTextDocument();
  3. myDocumentCursor = new QTextCursor(parsedDocument);
  4.  
  5. QTextCharFormat textFormat = myDocumentCursor->charFormat();
  6. textFormat.setFontFamily("Courier");
  7. myDocumentCursor->setCharFormat(textFormat);
  8.  
  9.  
  10. QString formattedString;
  11. formattedString = QString("This is th Data of Some object. It was retrieved on %2\r\n").arg(QDateTime::currentDateTime().toString());
  12. myDocumentCursor->insertText(formattedString);
  13.  
  14. myDocumentCursor->insertBlock();
  15.  
  16. formattedString = QString("Epoch").leftJustified(21, ' ');
  17. formattedString.append(QString("Position x-Axis").leftJustified(21, ' '));
  18. formattedString.append(QString("Position y-Axis").leftJustified(21, ' '));
  19. formattedString.append(QString("Position z-Axis").leftJustified(21, ' '));
  20. formattedString.append(QString("Velocity x-Axis").leftJustified(21, ' '));
  21. formattedString.append(QString("Velocity y-Axis").leftJustified(21, ' '));
  22. formattedString.append(QString("Velocity z-Axis").leftJustified(16, ' '));
  23. myDocumentCursor->insertText(formattedString);
  24.  
  25. myDocumentCursor->insertBlock();
  26.  
  27. formattedString.clear();
  28.  
  29. for(int i = 0; i < time.size(); i++){
  30.  
  31. formattedString = QString("%1 %2 %3 %4 %5 %6 %7").arg(time[i], -16, 'f', -1)
  32. .arg(pos[i][0], -16, 'f', -1).arg(pos[i][1], -16, 'f', -1).arg(pos[i][2], -16, 'f', -1)
  33. .arg(vel[i][0], -16, 'f', -1).arg(vel[i][1], -16, 'f', -1).arg(vel[i][2], -16, 'f', -1);
  34.  
  35. myDocumentCursor->insertText(formattedString);
  36. myDocumentCursor->insertBlock();
  37. }
  38.  
  39. return parsedDocument;
  40.  
  41. }
To copy to clipboard, switch view to plain text mode 

Basically this works out quite smoothly, just takes a few minutes as I have roughly 500K lines of data. But there are 2 major problems that I ran into: 1. The memory usage after putting all data into the Document is around 1.2GB, 2. It takes a HUGE amount of time(~15min) to display the document in a QTextEdit (via QTextEdit::setDocument(QTextDocument*)).

So obviously I am doing something wrong. So do you guys have an idea what I should be doing differently?