Storing and displaying "large" amoung of data in QTextEdit

  • 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):

    QTextDocument* parseDoc(std::vector<double>& time, std::vector<std::array<double,3>>& pos, std::vector<std::array<double,3>>& pos){
    parsedDocument = new QTextDocument();
    myDocumentCursor = new QTextCursor(parsedDocument);

    QTextCharFormat textFormat = myDocumentCursor->charFormat();

        QString formattedString;

    formattedString = QString("This is th Data of Some object. It was retrieved on %2\r\n").arg(QDateTime::currentDateTime().toString());


    formattedString = QString("Epoch").leftJustified(21, ' ');
    formattedString.append(QString("Position x-Axis").leftJustified(21, ' '));
    formattedString.append(QString("Position y-Axis").leftJustified(21, ' '));
    formattedString.append(QString("Position z-Axis").leftJustified(21, ' '));
    formattedString.append(QString("Velocity x-Axis").leftJustified(21, ' '));
    formattedString.append(QString("Velocity y-Axis").leftJustified(21, ' '));
    formattedString.append(QString("Velocity z-Axis").leftJustified(16, ' '));



    for(int i = 0; i < time.size(); i++){

    formattedString = QString("%1 %2 %3 %4 %5 %6 %7").arg(time[i], -16, 'f', -1)
    .arg(pos[i][0], -16, 'f', -1).arg(pos[i][1], -16, 'f', -1).arg(pos[i][2], -16, 'f', -1)
    .arg(vel[i][0], -16, 'f', -1).arg(vel[i][1], -16, 'f', -1).arg(vel[i][2], -16, 'f', -1);


        return parsedDocument;



    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?

  • You will probably get better performance if you add some line endings "\n".

Log in to reply

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.