Results 1 to 13 of 13

Thread: QTextEdit loading takes long time

  1. #1
    Join Date
    Feb 2006
    Posts
    60
    Thanks
    21
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default QTextEdit loading takes long time

    hi,
    I am using QTextEdit to display large files (containing more than 500000 lines). (around 2 min.). I am also using Syntax Highlighter for coloring of the lines

    It take long time to load it, as i display the contents after reading the complete file (show.).
    My complete application is blocked for that time and i cannot operate on other widgets.

    Is there anyway, to display a part of file (with sytax highlighting) and process the file later on in the backend and add it to the editor.

    Please post if any code snippets are available.

    Thanking you,

    regards,
    sree

  2. #2
    Join Date
    Jan 2006
    Location
    Kerala
    Posts
    371
    Thanks
    76
    Thanked 37 Times in 32 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QTextEdit loading takes long time

    Use QTimer / Thread to load the parts of file or while loading call processEvents

    It's Better to read this first

    http://www.ics.com/developers/papers/?cont=get_paper&paper_key=turbo
    We can't solve problems by using the same kind of thinking we used when we created them

  3. #3
    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: QTextEdit loading takes long time

    To load your text faster a QTimer::singleShot() will help and about the highlighting you'll have to optimize as much as possible (understand : drop reg exps and think about the optimal parsing char by char...)
    Current Qt projects : QCodeEdit, RotiDeCode

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

    Default Re: QTextEdit loading takes long time

    I'd say that loading 500k lines of text into a simple text editor like QTextEdit is nothing but a suicide
    How exactly do you load it? Using QTextDocument or QTextEdit::setPlainText() or simmilar?

  5. #5
    Join Date
    Feb 2006
    Posts
    60
    Thanks
    21
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: QTextEdit loading takes long time

    I load the text using setPlainText(text)

    regards

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

    Default Re: QTextEdit loading takes long time

    Quote Originally Posted by sreedhar
    I load the text using setPlainText(text)
    That's why it takes so much time. You should create a QTextDocument first and then use QTextEdit::setDocument() to make QTextEdit display it. It should operate much faster on the text then.

  7. The following user says thank you to wysota for this useful post:

    sunil.thaha (16th June 2006)

  8. #7
    Join Date
    Jan 2006
    Posts
    368
    Thanks
    14
    Thanked 18 Times in 17 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QTextEdit loading takes long time

    I have tried loading the text on a separate timer, as described here on this thread. This leads to a fist and fast disaplay, and then the UI gets freezed for several seconds. I also tried some sort of thread test, and still got the same effect with much uglier code.

    I will try the example described here with the separate QTextDocument. This might solve some issues.

    But still, the problem may be the slow paiting in the syntax highlighter, can you show some code?

  9. #8
    Join Date
    Jan 2006
    Posts
    75
    Thanks
    3
    Thanked 5 Times in 4 Posts
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: QTextEdit loading takes long time

    sunil.thaha, i cannot access the URL you provided, it always say my email is invalid (the textbox is in red color), are you a member in ICS that's why you can access it?

    Quote Originally Posted by sunil.thaha
    Use QTimer / Thread to load the parts of file or while loading call processEvents

    It's Better to read this first

    http://www.ics.com/developers/papers/?cont=get_paper&paper_key=turbo

  10. #9
    Join Date
    Mar 2006
    Location
    Vadodara, Gujarat, India
    Posts
    65
    Thanks
    16
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QTextEdit loading takes long time

    Quote Originally Posted by ball
    sunil.thaha, i cannot access the URL you provided, it always say my email is invalid (the textbox is in red color), are you a member in ICS that's why you can access it?
    U r right ball .... i also can't access the link .... same problem as u .... says not a valid email ..... and turns red ....Sunil .... can u upload the doc if u have it ??
    Do what u r afraid to do, and the death of fear is sure.

  11. #10
    Join Date
    Jan 2006
    Location
    Kerala
    Posts
    371
    Thanks
    76
    Thanked 37 Times in 32 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QTextEdit loading takes long time

    Well , I used my company's email id to get the docs.
    and Unfortunately the company does not let any attachments out.

    I think mostly all the guys here have that doc.


    Anyway pm me your email id's and If i can I will copy paste it and send
    We can't solve problems by using the same kind of thinking we used when we created them

  12. #11
    Join Date
    May 2006
    Posts
    788
    Thanks
    49
    Thanked 48 Times in 46 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: QTextEdit loading takes long time

    Build a less (unix http://linux.about.com/library/cmd/blcmdl1_less.htm ) similar function .... and limit him to 20-30 line....

    and as slot a vertical slider...... tickintervall 30-20

    and get line from file ..... chanche this code to get line start and end...

    is very fast....

    Qt Code:
    1. QString Sqlitedb::file_get_line(QString fullFileName,int linenr)
    2. {
    3. QString result;
    4. QFile file( fullFileName );
    5. if( file.open( QIODevice::ReadOnly | QIODevice::Text ) ) {
    6. QTextStream in( &file );
    7. int currentLineNr = 0; // or 1
    8. while( ! in.atEnd() ) {
    9. QString line( in.readLine() );
    10. if( currentLineNr == linenr ) { /* only rewrite here .. lineNr */
    11. result = line;
    12. break;
    13. }
    14. currentLineNr += 1;
    15. /*qDebug() << "### linerr " << currentLineNr; */
    16. }
    17. }
    18. return result;
    19. }
    To copy to clipboard, switch view to plain text mode 

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

    Default Re: QTextEdit loading takes long time

    This would be a crude and nasty hack which would break all of QTextEdit functionality like redo/undo, searching for text, etc. The proper way is to use QTextDocument. Trust me on that If in doubt, read the docs.

  14. The following user says thank you to wysota for this useful post:

    sreedhar (20th June 2006)

  15. #13
    Join Date
    Jul 2010
    Posts
    6
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QTextEdit loading takes long time

    Comment. I meet same question.

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.