我想在 Qt 中解析 HTML 字符串,
基本上我有QTextEdit
对象(允许富文本),当有人在QTextEdit
中粘贴富文本(从MSWORD或类似内容复制)时,我想要样式信息。
我有自己的结构来存储样式信息,如下所示。谁能告诉我在从 QTextEdit 获取 html 后如何解析 HTML? 任何现有的方法?,
P.S:我使用的是QT版本4.1.4(由于项目原因),所以我不能使用4.1.4之后添加的QT类。
提前致谢。
typedef struct styleset {
QString font;
QString size;
bool bold;
bool italics;
bool underline;
QString color;
}STYLESET;
最佳答案
我认为您可以创建一个 QDomDocument
,然后使用 QDomDocument::setContent( const QString & text, ...)
设置其内容。
Qt 4.1 文档说:
This function reads the XML document from the string text. Since text is already a Unicode string, no encoding detection is done.
一旦加载了QDomDocument
,您就可以使用节点、属性等来填充您的结构。
关于html - 在QT中解析HTML字符串,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6454127/