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. [SOLVED] Copying contents from one QTextBrowser to another

[SOLVED] Copying contents from one QTextBrowser to another

Scheduled Pinned Locked Moved General and Desktop
2 Posts 1 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.
  • A Offline
    A Offline
    amban
    wrote on last edited by
    #1

    Hi All,
    I have 2 QTextBrowsers. I read contents of one of them as a QTextDocument. Now i want to find lines containing a string within this document and copy the line as setText for the other QTextBrowser. How should i do it ?

    E.g. TextBrowser A has
    abc...
    pqr...
    xyz....

    Suppose i search for "xyz"
    Then i want to copy line xyz... to new QTextBrowser

    @
    QString input = findstring->text().trimmed(); //string to be searched

     QTextDocument *document = jobmessagebrowser->document();
    
     if(!input.isEmpty())
     {
         QTextCursor highlightcursor(document);
         QTextCursor cursor(document);
    
         cursor.beginEditBlock();
    
         while(!highlightcursor.isNull() && !highlightcursor.atEnd())
         {
             highlightcursor.position();
             highlightcursor = document->find(input, highlightcursor, QTextDocument::FindWholeWords);
    
             if(!highlightcursor.isNull())
             {
                 grepbrowser->setText(???); //what should be here ?
             }
         }
    
     }
    

    @

    Thanks a lot.

    1 Reply Last reply
    0
    • A Offline
      A Offline
      amban
      wrote on last edited by
      #2

      Hi All,
      I found the answer....

      @
      if(!highlightcursor.isNull())
      {
      grepbrowser->append(highlightcursor.block().text());
      }
      @

      Hope this helps someone.

      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