maxchirag
maxchirag

Reputation: 549

Parsing HTML String in QT

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;

Upvotes: 2

Views: 1520

Answers (2)

Dan Milburn
Dan Milburn

Reputation: 5718

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

Upvotes: 0

Thomas Vincent
Thomas Vincent

Reputation: 2224

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.

Upvotes: 3

Related Questions