QT读取xml文件,获取标签中的内容,看了好几篇教程,没看懂

xml文件是这样


<?xml version="1.0" encoding="UTF-8"?>
<students>
    <student>
        <姓名>小菲</姓名>
        <年龄>20</年龄>
        <班级>3班</班级>
    </student>
    <student>
        <姓名>林聪</姓名>
        <年龄>18</年龄>
        <班级>1班</班级>
    </student>
    <student>
        <姓名>黄牛</姓名>
        <年龄>21</年龄>
        <班级>2班</班级>
    </student>
</students>
QString path=QCoreApplication::applicationDirPath()+"/test.xml";
QFile file(path);
if (!file.open(QFile::ReadOnly))
{
    return;
}
QDomDocument doc;
doc.setContent(&file);
file.close();
QDomElement root = doc.documentElement();
QDomNode node = root.firstChild();
while (!node.isNull())
{
    //一个student节点
    if (node.isElement())
    {
        QDomElement e = node.toElement();
        QDomNodeList list = e.childNodes();
        for (int i = 0; i < list.count(); i++)
        {
            QDomNode n = list.at(i);
            qDebug()<<n.nodeName();  //属性
            qDebug()<<n.toElement().text(); //文本
        }
    }
    node = node.nextSibling();
}