Nesta página

Utils::PersistentSettingsReader Class

class Utils::PersistentSettingsReader

A classe `PersistentSettingsReader` lê um ` QVariantMap ` com estruturas de dados arbitrárias e aninhadas a partir de um arquivo XML. Mais...

Header: #include <PersistentSettingsReader>

Descrição detalhada

Lida com todos os tipos simples serializáveis como string, bem como com QVariantList e QVariantMap. Exemplo:

<qtcreator>
    <data>
        <variable>ProjectExplorer.Project.ActiveTarget</variable>
        <value type="int">0</value>
    </data>
    <data>
        <variable>ProjectExplorer.Project.EditorSettings</variable>
        <valuemap type="QVariantMap">
            <value type="bool" key="EditorConfiguration.AutoIndent">true</value>
        </valuemap>
    </data>

Ao analisar a estrutura, uma pilha de análise do tipo `ParseValueStackEntry` é usada para cada elemento `<data>`. `ParseValueStackEntry` é uma variante/união de:

  • valor simples
  • mapa
  • lista

É possível registrar funções de serialização em string para tipos personalizados, registrando-as no sistema de tipos Qt Meta. Exemplo:

QMetaType::registerConverter(&MyCustomType::toString);
QMetaType::registerConverter<QString, MyCustomType>(&myCustomTypeFromString);

Ao entrar em um elemento de valor ( <value> / <valuelist>, <valuemap> ), a entrada é inserida na pilha de acordo com o tipo. Ao sair do elemento, o valor QVariant da entrada é retirado da pilha e adicionado à entrada seguinte na pilha (adicionado à lista ou inserido no mapa). O primeiro elemento da pilha é o valor do elemento <data>.

Veja também Utils::PersistentSettingsWriter.

Copyright © The Qt Company Ltd. and other contributors. Documentation contributions included herein are the copyrights of their respective owners. The documentation provided herein is licensed under the terms of the GNU Free Documentation License version 1.3 as published by the Free Software Foundation. Qt and respective logos are trademarks of The Qt Company Ltd in Finland and/or other countries worldwide. All other trademarks are property of their respective owners.