Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-103350

QTextCursor movePosition() sometimes won't reach the end of text

    XMLWordPrintable

Details

    • Bug
    • Resolution: Unresolved
    • P3: Somewhat important
    • None
    • 5.15.2
    • GUI: Text handling
    • None
    • Linux: Debian testing
    • Linux/X11

    Description

      I'm writing an app which uses a QTextEdit to contain text. It also uses hunspell to check spelling, and for that, I use QTextCursor::movePosition() to move from word to word. The code looks like this:

      // code placeholder
      do { 
         while (cursor.movePosition(QTextCursor::EndOfWord, QTextCursor::KeepAnchor)) {
             textEdit->setTextCursor(cursor); QString word = cursor.selectedText();
       // etc
      // Move to the next word
      >if (! cursor.movePosition(QTextCursor::NextWord, QTextCursor::MoveAnchor))
       break;
       } 
      }
       while (cursor.movePosition(QTextCursor::NextBlock, QTextCursor::MoveAnchor)); 
      

       

      I've found that, if the text contains something like

      word word word1

      <blank line>

      <space: one or more> word2 word2 word2

      then movePosition(QTextCursor::NextWord, QTextCursor::MoveAnchor) won't move past word1: it returns false, and we break out of the loop.

      Also, if there's another line below it that doesn't have leading spaces, as

      <space: one or more> word2 word2 word2

      <blank line

      word3 word4 word5

      then it'll proceed to word5.

       

      Yes, I know it's confusing, which is probably why it's not been reported before (as far as I can tell). Sorry if I've messed up the code view: this is my first bug report for you.
       

      Attachments

        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

        Activity

          People

            esabraha Eskil Abrahamsen Blomfeldt
            rjmx Ron Murray
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:

              Gerrit Reviews

                There are no open Gerrit changes