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. [Solved] Loading a file larger than 5.242.880 bytes insert newline in QPlainTextEdit
QtWS25 Last Chance

[Solved] Loading a file larger than 5.242.880 bytes insert newline in QPlainTextEdit

Scheduled Pinned Locked Moved General and Desktop
6 Posts 2 Posters 1.9k Views
  • 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.
  • W Offline
    W Offline
    Woomla
    wrote on last edited by
    #1

    Below is a scheme I use to load a large file. But when the file exceeds 5,242,880 bytes, an extra new line is inserted. So character 5.242.881 is inserted on the next line.

    I've created a text file with 32767 lines of exactly 160 bytes (including 2 bytes for \r\n, thus 158 characters + \r\n).
    Line 32768 has exactly 80 characters. This file load fine.

    When I add 1 character to line 32768, this character will be displayed on a new line. Obviously not correct.

    Is this a bug in my code or somewhere else?

    @void MainWindow::openFile(QString filePath)
    {
    ui->plainTextEdit->clear();
    file->setFileName(filePath);
    if (file->open(QFile::ReadOnly))
    QTimer::singleShot(10, this, SLOT(readFilePart()));

    startRead.start();
    ui->plainTextEdit->viewport()->setCursor(Qt::WaitCursor);
    ui->plainTextEdit->setUpdatesEnabled(false);
    }

    void MainWindow::readFilePart()
    {
    qint64 bytesRead = file->read(buffer, bufsize - 1);
    buffer[bytesRead] = 0;
    ui->plainTextEdit->appendPlainText(buffer);

    qDebug() << "duration:" << startRead.elapsed() << ", bytesRead:" << bytesRead;

    if (bytesRead == bufsize - 1)
    QTimer::singleShot(10, this, SLOT(readFilePart()));
    else
    {
    qDebug() << "rest: {" << buffer << "}";
    QTimer::singleShot(10, this, SLOT(closeFile()));
    }
    }

    void MainWindow::closeFile()
    {
    file->close();
    ui->plainTextEdit->setUpdatesEnabled(true);
    ui->plainTextEdit->viewport()->unsetCursor();
    }
    @

    project files are at:
    "MainWindow.ui":http://pastebin.com/2AYnPe1L
    "MainWindow.h":http://pastebin.com/x327G261
    "MainWindow.cpp":http://pastebin.com/8bx1havh

    1 Reply Last reply
    0
    • T Offline
      T Offline
      tobias.hunger
      wrote on last edited by
      #2

      So if you think there is a bug: "File a bug report":https://bugreports.qt-project.org/ . Talking about it here will unfortunately not get it fixed:/

      1 Reply Last reply
      0
      • W Offline
        W Offline
        Woomla
        wrote on last edited by
        #3

        Before filing a bug report I want to exclude making a bug myself :)

        [edit]Which I obviously failed to do ;-)[/edit]

        1 Reply Last reply
        0
        • W Offline
          W Offline
          Woomla
          wrote on last edited by
          #4

          https://bugreports.qt-project.org/browse/QTBUG-31174

          1 Reply Last reply
          0
          • T Offline
            T Offline
            tobias.hunger
            wrote on last edited by
            #5

            Well, the best person to find out whether it is a bug or not is the developer that wrote the code. If you file a bug report that person will notice the issue. If you post it to the forum the likelihood of that happening is way lower. And if you send attach a small project that demonstrates, then the time it takes to reproduce the issue should not be too big. It is pretty easy to reject a bug as invalid. It is much harder finding bugs that people talk about somewhere on the internet:)

            Before somebody suggests maintainers or whoever can just copy the issues from here into the bug tracker: That fails as soon as there is a question back to the user that had the problem. So that is not a solution.

            1 Reply Last reply
            0
            • W Offline
              W Offline
              Woomla
              wrote on last edited by
              #6

              This line
              @ui->plainTextEdit->appendPlainText(buffer);@

              inserts a newline after reading 65535 bytes in my example.

              Issue solved. See bugreport.

              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