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. Traversing a QTextDocument via QRegExp and QTextCursor
Forum Updated to NodeBB v4.3 + New Features

Traversing a QTextDocument via QRegExp and QTextCursor

Scheduled Pinned Locked Moved General and Desktop
1 Posts 1 Posters 712 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.
  • M Offline
    M Offline
    monoblaine
    wrote on last edited by
    #1

    Hello Community,

    I'm still all new to Qt and going to write a recognizer for a AsciiDoc Documentstructure.
    I choosed to do this with a list of QRegExp's.

    So if I do this, I get for '= 1 =' a correct result. But also for the following line. After the following line I don't get a result for '= 2 ='
    This means following:
    "
    asdf
    = 1 =
    bsdf
    = 2 =
    "
    should report a recognition for '= 1 =' and '= 2 ='. But my actual algorithm only reports
    "
    = 1 =
    asdf
    "

    I think I'm doing something wrong with the CursorMove.
    Can anybody help me ?

    Here's my algorithm:
    @
    foreach(QRegExp searchPattern, *asciiDocSyntax)
    {
    crs = doc->find(searchPattern, crs, QTextDocument::FindWholeWords);

            if(!crs.isNull())
            {
                crs.movePosition(QTextCursor::NextBlock, QTextCursor::KeepAnchor);
    
                qDebug() << "[parseDocument] found a matching block for pattern "
                         << searchPattern.pattern()
                         << " :" << crs.block().text();
            }
    

    }
    @

    with these QRegExp:
    @
    // Header 1
    asciiDocSyntax->push_back(QRegExp("^= .* =$"));

    // Header 2
    asciiDocSyntax->push_back(QRegExp("^== .* ==$"));
    

    @

    Thank you very much !

    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