gpt4 book ai didi

c++ - 如何使用 QT 创建带有 pair 标签的 Child

转载 作者:塔克拉玛干 更新时间:2023-11-03 07:12:44 32 4
gpt4 key购买 nike


我正在做一个项目,我必须使用 C++ 的 QT 库(QTDomDocument 等)在 XML 文档中写入信息。
问这个问题可能很愚蠢,但我正在寻找关于如何创建带有对标记的 XML 子节点的解决方案,例如,我有这个:

<color_space>
</color_space>

我想按照这个模式添加 x 个 child :

<color_space>
<color_plan>R</color_plan>
<color_plan>G</color_plan>
...
</color_space>

我尝试了多种不同的代码,据我所知,最相似的结果是:

<color_space>
<color_plan/>
<color_plan/>
...
</color_space>

谢谢大家的帮助。

最佳答案

好吧,我只是想出了如何做我想做的事情,我希望它能帮助其他人!

    // Here we have a QVector where we have all our color plan
QVector<QString>ColorPlanTable= { "R","G","B","L","a","b","Y","Cb","Cr" };

//sub_element is the Color_space element (parent node)
sub_element= sub_element.nextSiblingElement();

// Here we create a new element for color_plan (child of Color_space)
QDomElement NewColorPlan=document_->createElement("color_plan");

// And then we create a TextNode to add to the element color_plan
QDomText NewColorPlanText = document_->createTextNode(ColorPlanTable.at(i));

// Adding the element color_plan as a child of Color_space
sub_element.appendChild(NewColorPlan);

// And then adding the text of the color_plan!
NewColorPlan.appendChild(NewColorPlanText);

关于c++ - 如何使用 QT 创建带有 pair 标签的 Child,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38322648/

32 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com