[SOLVED] Copying contents from one QTextBrowser to another



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



  • Hi All,
    I found the answer....

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

    Hope this helps someone.


Log in to reply
 

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