Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. [solved] How to speed up performance the right way?
Qt 6.11 is out! See what's new in the release blog

[solved] How to speed up performance the right way?

Scheduled Pinned Locked Moved General and Desktop
4 Posts 2 Posters 3.6k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • J Offline
    J Offline
    Jan-Willem
    wrote on last edited by
    #1

    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?

    1 Reply Last reply
    0
    • J Offline
      J Offline
      Jan-Willem
      wrote on last edited by
      #2

      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... ;-)

      1 Reply Last reply
      0
      • SGaistS Offline
        SGaistS Offline
        SGaist
        Lifetime Qt Champion
        wrote on last edited by
        #3

        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 :)

        Interested in AI ? www.idiap.ch
        Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

        1 Reply Last reply
        0
        • J Offline
          J Offline
          Jan-Willem
          wrote on last edited by
          #4

          Thanks for the welcome.
          I've just marked this thread as solved.

          1 Reply Last reply
          0

          • Login

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • Users
          • Groups
          • Search
          • Get Qt Extensions
          • Unsolved