Trolltech Home | Qt-interest Home | Recent Threads | All Threads | Author | Date
All threads index page 2

Qt-interest Archive, September 2007
Qt 4.3.0 - how to get text from a QTextEdit?!?!


Message 1 in thread

How do I get the text from a QTextEdit?

The two functions listed in the help won't compile:

  'text' : is not a member of 'QTextEdit'
 'plainText' : is not a member of 'QTextEdit'




--
 [ signature omitted ] 

Message 2 in thread

I also scratched my head when I first looked at QTextEdit. You
have to use a QTextCursor. Here's some example code (without further
expaination) that I use to grab a line "near" the current cursor possition:

QString
OabConsole::getCommandLine()
{
    QTextCursor lCursor = m_textEdit->textCursor();
    // move to end of previous line
    lCursor.movePosition(QTextCursor::PreviousCharacter,
                         QTextCursor::MoveAnchor,/*count*/1);
    lCursor.movePosition(QTextCursor::StartOfLine,
                         QTextCursor::KeepAnchor,/*count*/1);
    QString line = lCursor.selectedText();
    //qcerr() << "line: '" << line << "'" << endl;
    //qcerr() << "line unicode: ";
    //IcmQT::debugOutQString(line,qcerr());

    //remove prompt from front of line (if present)
    if ( line.startsWith(m_normalPrompt) ) {
        line = line.remove(/*starting*/0,/*amount*/m_normalPrompt.size());
        return line;
    }
    if ( line.startsWith(m_continuePrompt) ) {
        line = line.remove(/*starting*/0,/*amount*/m_continuePrompt.size());
    }
    return line;
}


John Smith wrote:
> How do I get the text from a QTextEdit?
>
> The two functions listed in the help won't compile:
>
>   'text' : is not a member of 'QTextEdit'
>  'plainText' : is not a member of 'QTextEdit'
>
>
>
>
> --
> To unsubscribe - send a mail to qt-interest-request@xxxxxxxxxxxxx with "unsubscribe" in the subject or the body.
> List archive and information: http://lists.trolltech.com/qt-interest/
>
>   

--
 [ signature omitted ] 

Message 3 in thread

Use toPlainText() to get the current text.

Use setPlainText() to set the text.

plainText is a property of the QTextEdit, which is you have to use
set/get methods to access this property.

http://doc.trolltech.com/4.3/qtextedit.html (You can click on the
plaintext property to see the accessor functions)


-----Original Message-----
From: Peter Hackett [mailto:peter@xxxxxxxxxxxx] 
Sent: Friday, September 07, 2007 12:12 PM
To: John Smith
Cc: qt-interest@xxxxxxxxxxxxx
Subject: Re: Qt 4.3.0 - how to get text from a QTextEdit?!?!

I also scratched my head when I first looked at QTextEdit. You
have to use a QTextCursor. Here's some example code (without further
expaination) that I use to grab a line "near" the current cursor
possition:

QString
OabConsole::getCommandLine()
{
    QTextCursor lCursor = m_textEdit->textCursor();
    // move to end of previous line
    lCursor.movePosition(QTextCursor::PreviousCharacter,
                         QTextCursor::MoveAnchor,/*count*/1);
    lCursor.movePosition(QTextCursor::StartOfLine,
                         QTextCursor::KeepAnchor,/*count*/1);
    QString line = lCursor.selectedText();
    //qcerr() << "line: '" << line << "'" << endl;
    //qcerr() << "line unicode: ";
    //IcmQT::debugOutQString(line,qcerr());

    //remove prompt from front of line (if present)
    if ( line.startsWith(m_normalPrompt) ) {
        line =
line.remove(/*starting*/0,/*amount*/m_normalPrompt.size());
        return line;
    }
    if ( line.startsWith(m_continuePrompt) ) {
        line =
line.remove(/*starting*/0,/*amount*/m_continuePrompt.size());
    }
    return line;
}


John Smith wrote:
> How do I get the text from a QTextEdit?
>
> The two functions listed in the help won't compile:
>
>   'text' : is not a member of 'QTextEdit'
>  'plainText' : is not a member of 'QTextEdit'
>
>
>
>
> --
> To unsubscribe - send a mail to qt-interest-request@xxxxxxxxxxxxx with
"unsubscribe" in the subject or the body.
> List archive and information: http://lists.trolltech.com/qt-interest/
>
>   

--
 [ signature omitted ] 

Message 4 in thread

You might be looking at the help for 3.x. The functions you want are:

toPlainText()
toHtml()

--Justin

-----Original Message-----

From:  "John Smith" <invalid@xxxxxxxxxxx>
Subj:  Qt 4.3.0 - how to get text from a QTextEdit?!?!
Date:  Fri Sep 7, 2007 2:00 pm
Size:  371 bytes
To:  qt-interest@xxxxxxxxxxxxx

How do I get the text from a QTextEdit?

The two functions listed in the help won't compile:

  'text' : is not a member of 'QTextEdit'
 'plainText' : is not a member of 'QTextEdit'




--
 [ signature omitted ]