Incorrect order of attributes in Qt XML

后端 未结 4 574
迷失自我
迷失自我 2021-01-18 15:18

I have the following code:

element.clear();
element.setTagName(\"accountpoint\");
element.setAttribute(\"code\", QString(ID_CONST)+serial);
element.setAttrib         


        
4条回答
  •  抹茶落季
    2021-01-18 16:14

    I ran into this issue when trying to store xml setting data in git. In this case (in order to get a sane diff) it is important to store the xml using the same attribute ordering each time. The code base was several years old, using the deprecated Qt Xml instead of the newer QXmlStreamWriter.

    The trick of setting the QT_HASH_SEED environment variable (from @MrEricSir's answer) works well in this case. However, it can also be done directly in code, like in this example:

    qSetGlobalQHashSeed(42); // set a fixed hash value
    
    QDomDocument doc = QDomDocument(); 
    // add stuff to doc...
    // ...
    
    // save doc to file:
    QFile file(filename);
    QTextStream stream(&file);
    stream << doc.toString(4);
    file.close();
    
    // reset hash seed with new random value.
    qSetGlobalQHashSeed(-1);
    

    This way, the rest of your application works as before, thus avoiding exposure to algorithmic complexity attacks.

提交回复
热议问题