20,241
社区成员




<?xml version="1.0" encoding="UTF-8" ?>
<historyrecords>
<record id="01">
<injectamount>100</injectamount>
<speedtime>0.5</speedtime>
<psi>1200</psi>
<time>0.6</time>
<status>good</status>
</record>
<record id="02">
<injectamount>110</injectamount>
<speedtime>0.6</speedtime>
<psi>1100</psi>
<time>0.3</time>
<status>bad</status>
</record>
</historyrecords>
void historyrecords::showhisrecords() {
QDomDocument doc;
QFile file("recordshistoryrecords.xml");
QString errorStr;
int errorLine;
int errorCol;
//setContent是将指定的内容指定给QDomDocument解析,
//第一参数可以是QByteArray或者是文件名等
if(!doc.setContent(&file,true,&errorStr,&errorLine,&errorCol))
{
//如果出错,则会进入这里。errorStr得到的是出错说明
//errorLine和errorCol则是出错的行和列
qDebug() << errorStr << "line: " << errorLine << "col: " << errorCol;
}
QDomNode firstNode = doc.firstChild();
qDebug() << qPrintable(firstNode.nodeName()) << qPrintable(firstNode.nodeValue());
}
void historyrecords::showhisrecords() {
QDomDocument doc;
QFile file("recordshistoryrecords.xml");
file.open(QIODevice::ReadOnly);
QString errorStr;
int errorLine;
int errorCol;
//setContent是将指定的内容指定给QDomDocument解析,
//第一参数可以是QByteArray或者是文件名等
if(!doc.setContent(&file,true,&errorStr,&errorLine,&errorCol))
{
//如果出错,则会进入这里。errorStr得到的是出错说明
//errorLine和errorCol则是出错的行和列
qDebug() << errorStr << "line: " << errorLine << "col: " << errorCol;
}
file.close();
QDomNode firstNode = doc.firstChild();
qDebug() << qPrintable(firstNode.nodeName()) << qPrintable(firstNode.nodeValue());
}
QFile file("recordshistoryrecords.xml");
->这段代码是不行的QFile file("F:/share/injector-gui2/recordshistoryrecords.xml");
->这段代码是行的QFile file(":/recordshistoryrecords.xml");
->这段代码是行的,前提是你的文件在qrc里面加进来了.