[solved] How to speed up performance the right way?
-
I am working on a writing application. Basicly is does the following:
1 - input in a QTextEdit including some custom markdown;
2 - using a QSyntaxHighlighter to highlight the custom markdown;
3 - through the textChanged-signal the html-preview get updated as follows:- the text of QTextEdit is copied to a QPlainTextEdit (just for convience, so i can see if this step goes right);
- in the QPlainTextEdit the custom markdown gets converted to html by another QSyntaxHighlighter;
- the html is set in a QTextBrowser.
The problem is the performance of step 3. I suppose the constantly loading of text into QPlainTextEdit and QTextBrowser and the use of the second QSyntaxHighlighter slow things down. So far I have in inserted qApp->processEvents() in the updatePreview-function and use a QTimer to update the preview less frequently, say once a second. It does works, but there still is a delay when typing the text in QTextEdit.
Perhaps another option would be using a separate thread for updating the preview. I was experimenting with QtConcurrentRun (I could not get it to work yet). But I also read on this forum that the use of a thread usually is not necessary.
And last but not least, I am working on using one and not two QSyntaxHighlighters to do the highlighting and the conversion and then send the html directly to QTextBrowser.
These are the steps I have already taken. My question is if someone could point me in the right direction for a better solution?
-
Well, it seems that writing down the problem helped me to find a solution.
After combining the two QSyntaxHighlighters into one an just replacing the changed text block in QPlainTextEdit instead of loading the whole text from QTextEdit, performance is what is should be.
So, thanks I guess... ;-) -
Hi and welcome to devnet !
Glad you found out and thanks for sharing the solution :)
Can you also please update the thread title prepending [solved] ? So other forum users may know a solution has been found :)
-
Thanks for the welcome.
I've just marked this thread as solved.