如何将 QString 转换为 QDomElement? [英] How to convert QString to QDomElement?

查看:132
本文介绍了如何将 QString 转换为 QDomElement?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经通过 element.text() 方法将 QDomElement 对象转换为 QString 并以文本格式存储在 mysql 数据库中.我在从数据库中提取它时遇到问题,因为从数据库中提取它的格式为 QString,所以我需要再次将其转换为 QDomElement 以便进一步使用该对象实现 smth.我该怎么做?

I've QDomElement object converted to QString via element.text() method and stored in mysql database in text format. I've a problem while extracting it from database, because having extracted from database it has a format of QString, so I need to convert it again to QDomElement in order to further implement smth with that object. How can I do this?

推荐答案

你可以把字符串解析成 QDomDocument 然后提取整棵树:

You can parse the string into a QDomDocument and then extract the whole tree:

QString input("<xml></xml>");
QDomDocument xmlDoc;
xmlDoc.setContent(input);
QDomElement output = xmlDoc.firstChild().toElement();

这篇关于如何将 QString 转换为 QDomElement?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆