2

I want to parse HTML String in Qt,

basically i have QTextEdit object (allowed rich text), and when some body paste Rich text (copied from MSWORD or similar) in QTextEdit, i want to have the style information.

I have my own structure to store the style imformation as below. can anyone tell me how can i parse HTML after i get the html from QTextEdit? any existing method?,

P.S : i am using QT version 4.1.4 (due to project reason) so i can't use QT classes added after 4.1.4.

Thanks in advance.

typedef struct styleset {
  QString font;
  QString size;
  bool bold;
  bool italics;
  bool underline;
  QString color;
}STYLESET;
1
  • Keep in mind that MsWord Rtf format is not the same as Qt rich text. QTextEdit don't recognize Rtf. Commented Jun 24, 2011 at 13:16

2 Answers 2

3

I think you can create a QDomDocument then set its content with QDomDocument::setContent( const QString & text, ...).

Qt 4.1 Doc says:

This function reads the XML document from the string text. Since text is already a Unicode string, no encoding detection is done.

Once you QDomDocument is loaded, you can mess around with nodes, attributes etc to fill your struct.

Sign up to request clarification or add additional context in comments.

Comments

0

Use QTextCursor to iterate through the QTextDocument associated with texteditor and retrieve character style information with QTextCursor::charFormat().

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.