[Qt-interest] 答复: 答复: how to quickly modify the value of attribute

pengliang(彭亮) pengliang at founder.com
Wed Oct 20 08:45:49 CEST 2010


Hi 

        This is my program: it’s successful to save. But have two problems, please see the pictures bellow.

 

 

     

 

 

 

 But, still have two problems:

 

 

 

 

________________________________

发件人: qt-interest-bounces at trolltech.com [mailto:qt-interest-bounces at trolltech.com] 代表 yanqzhi at gmail.com
发送时间: 2010年10月20日 12:48
收件人: qt-interest at trolltech.com
主题: [Qt-interest] 答复: how to quickly modify the value of attribute

 

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/20101020/036ae82b/attachment.html 
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: image/jpeg
Size: 32194 bytes
Desc: image001.jpg
Url : http://lists.qt-project.org/pipermail/qt-interest-old/attachments/20101020/036ae82b/attachment.jpe 
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: image/jpeg
Size: 99244 bytes
Desc: image002.jpg
Url : http://lists.qt-project.org/pipermail/qt-interest-old/attachments/20101020/036ae82b/attachment-0001.jpe 


More information about the Qt-interest-old mailing list