PDA

View Full Version : [UNSOLVED]QPlainTextEdit / QTextEdit performance issues using set or append methods



MW
27th July 2012, 17:12
Gd day,

I have read recently a topic named "QPlainTextEdit performance in Qt 4.7.0", as topic itself referred only to Qt 4.7.0 I started this one.

We can see that author wrote


...I've narrowed down by comenting stuff in my update method and it all comes to this

m_viewport->setPlainText(dataBuffer);

After that we can read that author himself "solved" the problem.


Happens the same on 4.7.2. So, compiled with 4.5.1 it's lighting fast, compiled with 4.7.0 and 4.7.2 it's amazingly slow

My case:

this->appendPlainText(finalLogContents);
Used as recommended in documentation with
setMaximumBlockCount = 80;
works the same as

this->setPlainText(finalLogContents);
Text in my QPlainTextEdit is refreshed every scroll made using either
QScrollBar or WheelEvent or PageDown - every time call to
setPlainText() consumes about 40% of 2.6 GHz CPU - it is way too much. Everytime variable named
finalLogContents consist of 80-100 lines depending on screen resolution.
I am thinking that maybe textChanged() SIGNAL is causing trouble - I will check it in a while with blockSignals().

Question:
Is there a method which use
char * instead of QString(I think it will be way faster cause I store all my data in
QByteArray
Should I revert to 4.5.1 or reimplement all crucial methods and create own fully customized TextEdit or maybe find another way using native QPlainTextEdit?

Thank you in advance, please post any even strange idea! :)

Edit 1:
Unfortunately textChanged SIGNAL is not causing my problem since it is not connected to any slot thus blocking it with QObject::blockSignals() gives nothing.

amleto
27th July 2012, 19:16
We can see that author wrote...

No, you can see. Nobody else can. Why didn't you link it?

Have you tried text modification using QTextCursor?

MW
27th July 2012, 19:22
We can see that author wrote...

No, you can see. Nobody else can. Why didn't you link it?

Have you tried text modification using QTextCursor?

You are more than right, but topic is very short - this explains my attitude ;)
http://www.qtcentre.org/threads/39266-QPlainTextEdit-performance-in-Qt-4-7-0
Regarding QTextCursor - I didn't try it - will do it in a couple of minutes.

amleto
27th July 2012, 19:37
additionally, have you made sure you are running a release build? (with the various iterator check disabling macros defined if you are using msvc and stl - yes, some are still enabled in release in studio 2005 and 2008 iirc)

MW
27th July 2012, 19:43
additionally, have you made sure you are running a release build? (with the various iterator check disabling macros defined if you are using msvc and stl - yes, some are still enabled in release in studio 2005 and 2008 iirc)

Yes tried release build both on MinGW and MSVC 2008 using Qt 4.8.0

Edit 1:
Tried using QTextCursor insertText() method without any luck still big CPU usage which causes sluggish GUI.
Pasting function which is responsible for setting text. CustomTextEdit inherits from QPlainTextEdit.



void CustomLogView::updateLogViewTextCursor(const QString &finalLogContents, const bool firstUpdate)
{
qDebug() << "CALL -> " + CommonFunctions::getCurrentTime();
//QString finalLogContents = "A";

if(firstUpdate)
{
this->document()->setPlainText(finalLogContents);
//this->appendPlainText(finalLogContents);
}
else
{
this->document()->setPlainText(finalLogContents);
QTextCursor cursor = this->textCursor();
int line = getLine(cursor);
int column = getIndex(cursor);

QTextBlock block = this->document()->begin();
int i = 0;
for( ; block != this->document()->end(); block = block.next(), ++i )
{
if(i == line)
{
cursor.setPosition(block.position() + column);
break;
}
}
this->setTextCursor(cursor);
}

}


Edit 2:
QTextCursor with insertText() mixed with beginBlockEdit() and endBlockEdit() gives me less sluggish GUI. Looks better, will try more fixes.

Edit 3:
Finally found some library code:

void QTextDocument::setPlainText(const QString &text)
{
Q_D(QTextDocument);
bool previousState = d->isUndoRedoEnabled();
d->enableUndoRedo(false);
d->beginEditBlock();
d->clear();
QTextCursor(this).insertText(text);
d->endEditBlock();
d->enableUndoRedo(previousState);
}

Using setPlainText() makes app slower (besides calling many functions in the chain) especially if you set enableUndoRedo(false).
Will research and revert with more info.

MW
28th July 2012, 09:25
Bumping thread a little.
Wondering if
drawContents() function in
QTextDocument will speed it up, anyone had experience with this?

DrQuade
1st October 2012, 14:05
Hi nearly the same Problem here have you found any solution so far ?

I have a 6MB big .txt file to read wich takes several minutes to show up in PlainTextEdit.

I think it is some kind of memory Problem which causes CPU usage to explode.

thx in advance