[Qt-interest] QPlainTextEdit and files larger than 1G

Roland Krause rokrau at yahoo.com
Wed Oct 28 17:51:22 CET 2009


Hello all.
Is there some sort of magic size limit on how large of a file a QPlainTextEdit can display. 

I am reading a rather large (~1.8G) file with the following code but after pretty much exactly 1000 blocks 
the application completely stalls. At that point memory consumption is about 3.6G res according to "top". 

Intersting though the block is read but the appendPlainText() doesn't return, just sits there (even over night :-) 

    QFile file(fName);
//    info.setFile(file);
    if (file.open(QIODevice::ReadOnly)) {
//        QTextStream stream(&file);
        pTextEdit->textCursor().beginEditBlock();
        const int nbuffer=1024*1024;
        char * buffer = new char[nbuffer];
        int iblocks=0;
        int nbytes;
        while ((nbytes=file.read(buffer,nbuffer))>0) {
            iblocks++;
            qDebug() << "read" << iblocks << "[M]";
            pTextEdit->appendPlainText(QString::fromAscii(buffer,nbytes));
            qDebug() << "and appended" ;
            if (iblocks%16==0) qApp->processEvents();
        }
        pTextEdit->textCursor().endEditBlock();
        success=true;
        delete [] buffer; 

The obvious: I have not set a "maximumBlockCount".

Now I know that there is a better way to do this given that I can load the document in parts and connect loading different parts to the position of the text cursor or scrollbars. Has anyone implemented this and is willing to share some code? Or point me into a direction where I can find some code for this? 

Also, I wonder how "kate" handles this since "kate" seems not to have any problems reading the file and scrolling thorugh it. 

Thanks for all pointers
Best regards

Roland
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.qt-project.org/pipermail/qt-interest-old/attachments/20091028/2b92b949/attachment.html 


More information about the Qt-interest-old mailing list