Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Storing and displaying "large" amoung of data in QTextEdit
Forum Updated to NodeBB v4.3 + New Features

Storing and displaying "large" amoung of data in QTextEdit

Scheduled Pinned Locked Moved General and Desktop
2 Posts 2 Posters 824 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • F Offline
    F Offline
    FreddyKay
    wrote on last edited by
    #1

    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();
    textFormat.setFontFamily("Courier");
    myDocumentCursor->setCharFormat(textFormat);

        QString formattedString;
    

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

    myDocumentCursor->insertBlock();

    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, ' '));
    myDocumentCursor->insertText(formattedString);

    myDocumentCursor->insertBlock();

        formattedString.clear();
    

    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);

    myDocumentCursor->insertText(formattedString);
    myDocumentCursor->insertBlock();
    }

        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?

    1 Reply Last reply
    0
    • M Offline
      M Offline
      msue
      wrote on last edited by
      #2

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

      1 Reply Last reply
      0

      • Login

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • Users
      • Groups
      • Search
      • Get Qt Extensions
      • Unsolved