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. Find & Advanced Find / Replace
QtWS25 Last Chance

Find & Advanced Find / Replace

Scheduled Pinned Locked Moved General and Desktop
5 Posts 3 Posters 2.3k Views
  • 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.
  • F Offline
    F Offline
    Forgive
    wrote on last edited by
    #1

    My current "Find" works like this:

    1.We move the QPlainTextEdit cursor to the Start.
    2.We do a while() loop by doing plainTextEdit->find(myTextToFind);
    3.If it's found, for now we just do qDebug() << "Found";

    It works pretty fine. But now i saw that something similar can be done with QTextBlock, but it works different of what i see. Since i can't do while() loop by doing myBlock->document()->find(myTextToFind) since it's a QTextCursor and i can't pass it to boolean.

    So what i want to do is to find text using QTextBlock instead, so i can retrieve line number of the string that you're searching for.

    1 Reply Last reply
    0
    • F Offline
      F Offline
      Forgive
      wrote on last edited by
      #2

      Bump? Sorry if it's not possible.

      1 Reply Last reply
      0
      • sierdzioS Offline
        sierdzioS Offline
        sierdzio
        Moderators
        wrote on last edited by
        #3

        Probably just didn't catch attention of people familiar with that topic. Happens :)

        I have no experience in QTextBlock, but instead I can propose something else: why not search using QString? Is it not feasible with QTextBlock? QString is pretty good when it comes to searching.

        (Z(:^

        1 Reply Last reply
        0
        • C Offline
          C Offline
          Chris H
          wrote on last edited by
          #4

          With [[Doc:QTextBlock]] one approach is to get the [[Doc:QTextList]] out of it, and then iterate over that list and search the [[Doc:QString]]s, as sierdzio suggests.

          1 Reply Last reply
          0
          • F Offline
            F Offline
            Forgive
            wrote on last edited by
            #5

            @
            QTextBlock myBlock;
            QPlainTextEdit *myEdit = new QPlainTextEdit();
            int index = 0;
            while(index < myEdit->document()->lineCount()) {
            myBlock = myEdit->document()->findBlockByLineNumber(index);
            if(myBlock.text().contains("#include")) {
            qDebug() << "FOUND!";

                }
                index++;
            }@
            

            I've got to that, though works fine. Hope it helps anyone ^^

            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