[Qt-interest] 答复: how to quickly modify the value of attribute
yanqzhi at gmail.com
yanqzhi at gmail.com
Wed Oct 20 06:48:04 CEST 2010
If you have read the qt examples firstly, you will found how to save.
bool save()
{
QTextStream textStream( &mFile );
QString filePath = mFile.fileName();
if(!mFile.isOpen())
{
if (mFile.open(QIODevice::WriteOnly))
{
mDoc.save( textStream, 4 ); // save as utf-8
if ( textStream.pos() == -1 || mFile.error() != QFile::NoError )
{
QMessageBox::critical(0, "", "Save xml failed");
return false;
}
}
mFile.close();
}
return true;
}
Sincerely yours,
yanqzhi at gmail.com
2010-10-20
======= 2010-10-20 11:41, your message: 答复: [Qt-interest]how to quickly modify the value of attribute =======
Hi
How to save it?
Thanks
彭亮 Ken
发件人: qt-interest-bounces at trolltech.com [mailto:qt-interest-bounces at trolltech.com] 代表 yanqzhi at gmail.com
发送时间: 2010年10月20日 10:45
收件人: qt-interest at trolltech.com
主题: Re: [Qt-interest]how to quickly modify the value of attribute
This method maybe help you.
Open a xml with read and write,
setAttribute(const QString &tagName, const QString &attributeName, const QString &value)
{
QDomNodeList nodeList = mDoc.elementsByTagName(tagName);
if (nodeList.length() < 1)
{
return false;
}
//I only change the first elment's attribute
QDomElement domElement = nodeList.at(0).toElement();
domElement.setAttribute(attributeName, value);
}
Sincerely yours,
yanqzhi at gmail.com
2010-10-20
======= 2010-10-20 10:28, your message: [Qt-interest] how to quickly modify the value of attribute=======
Hi All:
I don’t whether there is a good method to find an attribute and modify its value. (Normal method: open a xml with read only
And open new xml with write only, scan former xml one by one and write to new xml one by one, if find the attribute, write new value of attribute to new xml.)
I don’t want use this method. Anybody has other method?
Anybody has experience?
Thanks
彭亮 Ken
= = = = = = = = = = = = = = = = = = = =
= = = = = = = = = = = = = = = = = = = =
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.qt-project.org/pipermail/qt-interest-old/attachments/20101019/99d6ea76/attachment.html
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: image/jpeg
Size: 24788 bytes
Desc: not available
Url : http://lists.qt-project.org/pipermail/qt-interest-old/attachments/20101019/99d6ea76/attachment.jpe
More information about the Qt-interest-old
mailing list