문제

I need to read the a,b,c values(wheqre a,b,c are the name of some atributes) foreach node and list them in a table, but I don't know how to read the node values. Could you give an example code, please?

Thanks in advance

도움이 되었습니까?

해결책

QFile file("file.xml");
if (file.open(QIODevice::ReadOnly)) {
    QXmlStreamReader reader(file.readAll());
    file.close();
    while(!reader.atEnd()) {
        reader.readNext();
        if (reader.isStartElement()) {
            if (reader.name() == "node_name") {
                foreach(const QXmlStreamAttribute &attr, reader.attributes()) {
                    if (attr.name().toString() == QLatin1String("attribute_name")) {
                        QString attribute_value = attr.value().toString();
                        // do something
                    }
                }
            }
        }
    }
}
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top