PDA

View Full Version : QTextEdit loading takes long time



sreedhar
16th June 2006, 08:17
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

sunil.thaha
16th June 2006, 08:21
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 (http://www.ics.com/developers/papers/?cont=get_paper&paper_key=turbo)

fullmetalcoder
16th June 2006, 08:26
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...)

wysota
16th June 2006, 08:38
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?

sreedhar
16th June 2006, 11:15
I load the text using setPlainText(text)

regards

wysota
16th June 2006, 11:18
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.

elcuco
16th June 2006, 19:11
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?

ball
17th June 2006, 02:59
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?


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 (http://www.ics.com/developers/papers/?cont=get_paper&paper_key=turbo)

ankurjain
17th June 2006, 06:13
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 ??

sunil.thaha
18th June 2006, 09:03
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

patrik08
18th June 2006, 12:23
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....


QString Sqlitedb::file_get_line(QString fullFileName,int linenr)
{
QString result;
QFile file( fullFileName );
if( file.open( QIODevice::ReadOnly | QIODevice::Text ) ) {
QTextStream in( &file );
int currentLineNr = 0; // or 1
while( ! in.atEnd() ) {
QString line( in.readLine() );
if( currentLineNr == linenr ) { /* only rewrite here .. lineNr */
result = line;
break;
}
currentLineNr += 1;
/*qDebug() << "### linerr " << currentLineNr; */
}
}
return result;
}

wysota
19th June 2006, 14:08
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.

yeaiping
21st March 2011, 10:29
Comment. I meet same question.