Incorrect order of attributes in Qt XML

后端 未结 4 576
迷失自我
迷失自我 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 15:53

    I realize this is a partial answer to an old question, but if you just want the order of the attributes to be consistent every time there's a way to achieve this in Qt5.

    The reason for the inconsistent ordering is that the attributes are stored in a hash map. By default QHash randomizes its seed every time your application starts to guard against certain types of DDOS attacks. But there is a workaround:

    This randomization of QHash is enabled by default. Even though programs should never depend on a particular QHash ordering, there may be situations where you temporarily need deterministic behavior, e.g. for debugging or regression testing. To disable the randomization, define the environment variable QT_HASH_SEED. The contents of that variable, interpreted as a decimal value, will be used as the seed for qHash().

    So all you need to do is set an environment variable named QT_HASH_SEED that has a consistent value. For example you can set this in Qt Creator in the Projects tab:

    Where to set QT_HASH_SEED in the Run settings in the Project tab in Qt Creator

    This may or may not solve your problem, but it's super handy for unit testing.

提交回复
热议问题