[solved]Slow performances with QPlainTextEdit
-
Hello All,
I'm trying to make a custom TextEditor with some cool features, but I have a show stopper here its the perf of this widget...
I'm drag and dropping a 200Kb text file, and it takes approx 5s to load, where it's near to instantly on most of other standard text editor...I'm filling the widget like this:
@void logEditor::dropEvent(QDropEvent de)
{
// Unpack dropped data and handle it the way you want
const QMimeData mimeData = de->mimeData();// check for our needed mime type, here a file or a list of files if (mimeData->hasUrls()) { QList<QUrl> urlList = mimeData->urls(); // extract the local paths of the files for (int i = 0; i < urlList.size(); ++i) { QFile file(urlList.at(i).toLocalFile()); if (!file.open (QIODevice::ReadOnly)) return; QTextStream stream ( &file ); //QString line; setIsUpdating(); while( !stream.atEnd() ) { //line = stream.readLine(); this->appendPlainText(stream.readLine()); } file.close(); // when your done. setIsUpdating(false); } }
}@
I have also customized a few things, but I therefore disabling all painting events while i'm filling the text, with the setIsUpdating function.
I also even disabled all the fancy stuff to only have a QPlainTextEdit sublass with the drag and drop event and I still have this slowness.Full code of the editor can be seen here: http://pastebin.com/1jGtFTX8
I don't really know why is it so slow :/
Any ideas ?
-
One problem is definitely that you are appending ( especially if long texts).
It's basically adding strings together and updating it every single time when it's added.
Try building string in background and then only show it.
Or use insertPlaintText(QString); but it will automatically create new line. -
I'm doing like this now:
this->appendPlainText(stream.readAll());
and it works way better :)Thanks dude !
-
You'r welcome :) .
Please, mark thread as solved.Regards,
Jake -
hi,
How do I mark as solved, should I just put [solved] in title ?
-
Yep :-)