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
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
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...)
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?
Re: QTextEdit loading takes long time
I load the text using setPlainText(text)
regards
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.
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?
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
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 ??
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
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....
Code:
{
QFile file( fullFileName
);
int currentLineNr = 0; // or 1
while( ! in.atEnd() ) {
if( currentLineNr == linenr ) { /* only rewrite here .. lineNr */
result = line;
break;
}
currentLineNr += 1;
/*qDebug() << "### linerr " << currentLineNr; */
}
}
return result;
}
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.
Re: QTextEdit loading takes long time
Comment. I meet same question.