Results 1 to 4 of 4

Thread: Huge Text File

  1. #1
    Join Date
    Jan 2006
    Location
    Napoli, Italy
    Posts
    621
    Thanks
    5
    Thanked 86 Times in 81 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Huge Text File

    Hi to all!

    I have to show content of huge Text file (about 70 MB and 100000 lines).

    I tried with QTextEdit and QTextEdit::setPlainText but it's very slow.
    Also iterating the Text File and appending line like
    Qt Code:
    1. ...
    2. QFile file(fileName);
    3. file.open(QIODevice::ReadOnly | QIODevice::Text);
    4.  
    5. while(!file.atEnd())
    6. {
    7. textEdit->append(file.readLine());
    8. }
    9. file.close();
    10. ...
    To copy to clipboard, switch view to plain text mode 

    The file contents are truncated in textEdit.

    Help please
    A camel can go 14 days without drink,
    I can't!!!

  2. #2
    Join Date
    Mar 2006
    Posts
    140
    Thanks
    8
    Thanked 4 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Huge Text File

    This is just a brain dump of an approach I'd consider.
    Maybe there's another way of doing it.

    70mb really isn't a huge file by today's standards, but if it does seem slow then I'd recommend implementing a memory buffering mechanism that only reads enough to fill the QTextEdit.

    If your control is sized with 20 lines, then load 20 lines of text and display it.
    You could buffer 20 before and 20 after as well so as to have something to display whilst loading the next segment.

    One issue you'd need to deal with is the scrollbars. The bars by default will reflect upto 20 lines but it needs to think there's how ever many are actually in the file.
    Also if you need to edit the file then this technique would get much more complicated. You could have a structure that tracks the changes then separately from the control. Consider that the change disappears from sight you need to keep the change and redisplay it if it comes into focus again.
    It could also be very IO intensive so you'd be trading off the initial load time for another performance problem. Maybe increasing the buffer before and after to 2 or 3 times the size of the QTextEdit would help minimise IO.

    To implement this, I'd subclass QTextEdit to something like QtBufferedIOTextEdit to make it a reusable technique.

  3. #3
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Huge Text File

    If you use plain text, maybe you should try with QPlainTextEdit (it's probably available since 4.4) or with QTextBrowser?

  4. #4
    Join Date
    Jan 2006
    Location
    travelling
    Posts
    1,116
    Thanks
    8
    Thanked 127 Times in 121 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Huge Text File

    Quote Originally Posted by wysota View Post
    If you use plain text, maybe you should try with QPlainTextEdit (it's probably available since 4.4) or with QTextBrowser?
    I've not try QPlainTextEdit, which may perform well but I can ensure you than QTextEdit performs really bad when it comes to loading big files (even 1.2Mb requires a couple of seconds for the text to be laid out) and QTextBrowser does even worse... Looks like the doc for Qt 4.4 is available online yet btw...

    If you are looking for a faster alternatives you may have a look at QCodeEdit. It performs better than QTextEdit on average, in terms loading time and memory usage.QScintilla may also be worth a look but the API is very different which may make it harder to port your code...
    Current Qt projects : QCodeEdit, RotiDeCode

Similar Threads

  1. Unhandled exception in qatomic
    By NewGuy in forum Qt Programming
    Replies: 14
    Last Post: 23rd July 2013, 09:49
  2. Set up the Qt4.3.2 with Visual Studio 2005
    By lamoda in forum Installation and Deployment
    Replies: 6
    Last Post: 30th January 2008, 06:51
  3. How to read text only as it is from file
    By thomasjoy in forum Qt Programming
    Replies: 3
    Last Post: 9th August 2007, 08:47
  4. qt-3.3.8 fail in scratchbox
    By nass in forum Installation and Deployment
    Replies: 0
    Last Post: 25th May 2007, 15:21
  5. Editable text in QGraphicsView
    By wysota in forum Qt Programming
    Replies: 8
    Last Post: 24th February 2007, 15:30

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.