Important: Please read the Qt Code of Conduct -

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

  • 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)
    if (file->open(QFile::ReadOnly))
    QTimer::singleShot(10, this, SLOT(readFilePart()));


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

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

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

    void MainWindow::closeFile()

    project files are at:

  • Moderators

    So if you think there is a bug: "File a bug report": . Talking about it here will unfortunately not get it fixed:/

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

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

  • Moderators

    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.

  • This line

    inserts a newline after reading 65535 bytes in my example.

    Issue solved. See bugreport.

Log in to reply