开发者

Parsing HTML String in QT

开发者 https://www.devze.com 2023-03-15 02:41 出处:网络
I want to parse HTM开发者_运维百科L 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 ha

I want to parse HTM开发者_运维百科L 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;


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.


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

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号