如何使用 Qt 应用程序将 Id 添加到 kml 文件中的 "QDomElement" 标签

How to add Id to "QDomElement" tags in kml file using Qt application

我正在尝试将 ID 添加到 cpp 中的 QDomElements。我成功生成了一个 kml 文件。我想以增量方式将 id 添加到 kml 标签,如文档、地标。如何将 id 添加到 kml 文件中的标签。

    QDomProcessingInstruction header = createProcessingInstruction(QStringLiteral("xml"), QStringLiteral("version=\"1.0\" encoding=\"UTF-8\""));
    appendChild(header);

    QDomElement kmlElement = createElement(QStringLiteral("kml"));
    kmlElement.setAttribute(QStringLiteral("xmlns"), "http://www.opengis.net/kml/2.2");
   
    QDomElement m_rootDocumentElement;  m_rootDocumentElement = 
    createElement(QStringLiteral("Document"));
    kmlElement.appendChild(m_rootDocumentElement);
    for(int i = 0; i < qgeoCordinateList.count(); i++){
         QDomElement wpPlacemarkElement = createElement("Placemark");
       QDomElement wpPlacemarkElement1 = elementById("4");
        m_rootDocumentElement.appendChild(wpPlacemarkElement);
        wpPlacemarkElement.appendChild(wpPlacemarkElement1);
        addTextElement(wpPlacemarkElement, "name", QString::number(i+1));
        QDomElement pointElement = createElement("Point");
        wpPlacemarkElement.appendChild(pointElement);
        addTextElement(pointElement, "Index", QString::number(i));
    }

    QTextStream stream(&file);
    stream << header;
    stream << kmlElement;
    qDebug() << "kml Data :" << kmlElement.toElement().text().simplified();
    file.close();
To add Id into "QDomElement" tag add line where you want to add tag for QDomElement 
 
  wpPlacemarkElement.setAttribute(QStringLiteral("id"), QString::number(i)); 

// i is index of for loop
// add this line into for loop