Find & Advanced Find / Replace



  • 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.



  • Bump? Sorry if it's not possible.


  • Moderators

    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.



  • 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.



  • @
    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 ^^


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.