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. QSyntaxHighlighter hardly threadable
Forum Updated to NodeBB v4.3 + New Features

QSyntaxHighlighter hardly threadable

Scheduled Pinned Locked Moved Solved General and Desktop
8 Posts 4 Posters 1.1k Views 2 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
    jazzco2
    wrote on last edited by
    #1

    Re: How to avoid QSyntaxHighlighter::highlightBlock blocking the UI thread

    Hi all,

    like Krantz I've got the problem that the QSyntaxHighlighter blocks the ui while processing. I want to highlight really huge source files.

    The easiest way to break the chain would be to tell the highlighter just to highlight a bunch of lines, passing the processing back to do some ui things and then getting triggered to process the next bunch of lines. In case of changes in between this might be reprocessing some prior lines.

    But... I don't see any hook to get in there and stop the highlighter from doing all lines at once.

    The alternative plan which I'd like to avoid would be to copy my bunch of lines to an internal QTextDocument and have the highlighter only working on that. After processing the formats can be assigned to the big document. I don't feel really good with that overhead of copying.

    Any idea of doing that better?

    Regards

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

      Hi,

      You should likely take a look at the sources of QSyntaxHighlighter, you may find there how to accomplish what you want.

      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
      1
      • J Offline
        J Offline
        jazzco2
        wrote on last edited by
        #3

        Hi SGaist,

        I already read the sources. The only hook I found would be to suppress executing rehighlight by unsetting rehighlightPending. But I failed to get access to that flag of the private internal class.

        I think it's best to write my own interruptable highlighter as it seems to be a rather small class. Maybe I suggest adding a possibility to pause and resume the highlighting process to the qt team.

        Regards

        aha_1980A 1 Reply Last reply
        0
        • J jazzco2

          Hi SGaist,

          I already read the sources. The only hook I found would be to suppress executing rehighlight by unsetting rehighlightPending. But I failed to get access to that flag of the private internal class.

          I think it's best to write my own interruptable highlighter as it seems to be a rather small class. Maybe I suggest adding a possibility to pause and resume the highlighting process to the qt team.

          Regards

          aha_1980A Offline
          aha_1980A Offline
          aha_1980
          Lifetime Qt Champion
          wrote on last edited by
          #4

          Hi @jazzco2,

          Maybe I suggest adding a possibility to pause and resume the highlighting process to the qt team.

          You can file a suggestion at bugreports.qt.io (and please add a link to that here).
          Sometimes the developers can give you a hint for a solution too.

          Qt has to stay free or it will die.

          J 1 Reply Last reply
          1
          • cfdevC Offline
            cfdevC Offline
            cfdev
            wrote on last edited by
            #5

            highlightBlock(const QString &text) is really fast because cut huge file in many blocks.
            Maybe your process inside is not optimised ? do you use QRegularExpression ?

            J 1 Reply Last reply
            1
            • cfdevC cfdev

              highlightBlock(const QString &text) is really fast because cut huge file in many blocks.
              Maybe your process inside is not optimised ? do you use QRegularExpression ?

              J Offline
              J Offline
              jazzco2
              wrote on last edited by
              #6

              @cfdev said in QSyntaxHighlighter hardly threadable:

              highlightBlock(const QString &text) is really fast because cut huge file in many blocks.
              Maybe your process inside is not optimised ? do you use QRegularExpression ?

              No, regular expressions are too slow for my purpose. The problem is not the processing of highlightBlock but the fact that QSyntaxHighlighter isn't interruptable internally. It always runs through ALL lines on the first call which is triggered by the modification of the QTextDocument (that is internally directly connected to the private class).

              1 Reply Last reply
              0
              • aha_1980A aha_1980

                Hi @jazzco2,

                Maybe I suggest adding a possibility to pause and resume the highlighting process to the qt team.

                You can file a suggestion at bugreports.qt.io (and please add a link to that here).
                Sometimes the developers can give you a hint for a solution too.

                J Offline
                J Offline
                jazzco2
                wrote on last edited by
                #7

                @aha_1980 Thanks for the link. I filed a suggestion: https://bugreports.qt.io/browse/QTBUG-74701

                1 Reply Last reply
                2
                • J Offline
                  J Offline
                  jazzco2
                  wrote on last edited by
                  #8

                  Solution:
                  I created my own highlighter. It marks one or several disjoint regions as "dirty". Then it highlights an amount of lines shrinks the dirty region and if dirty regions remain it shoots a timer to resume highlighting later. If any change occurs on the document while highlighting it just adds a dirty region and keeps highlighting alive.

                  1 Reply Last reply
                  2

                  • Login

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