forked from ghlingjun/microseismic-data-analysis
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathreadconfig.cpp
More file actions
71 lines (64 loc) · 1.9 KB
/
Copy pathreadconfig.cpp
File metadata and controls
71 lines (64 loc) · 1.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
#include "readconfig.h"
#include <QMessageBox>
/**
* @author: Ethan
* @date: 2013-3-20
*/
ReadConfig::ReadConfig(const QString &fileName)
{
file = new QFile(fileName);
if(!file->open(QFile::ReadOnly | QFile::Text))
{
QMessageBox::critical(0,
"Load XML File Problem",
"Couldn't open xml file to load settings for database",
QMessageBox::Ok);
return;
}
doc = new QDomDocument();
if(!doc->setContent(file))
{
file->close();
return;
}
}
ReadConfig::~ReadConfig()
{
delete file;
file = 0;
delete doc;
doc = 0;
}
QString ReadConfig::getValue(const QString &nodeName)
{
QString result = "";
QDomElement docElem = doc->documentElement(); // 返回根元素
QDomNode n = docElem.firstChild(); // 返回根节点的第一个子节点
while(!n.isNull()) // 如果节点不为空
{
if (n.isElement()) //如果节点是元素
{
QDomElement e = n.toElement(); //将其转换为元素
// 返回元素标记
qDebug() << qPrintable(e.tagName());
// << qPrintable(e.attribute("id")); // 返回元素id属性的值
QDomNodeList list = e.childNodes(); // 获得元素 e 的所有子节点的列表
for(int i=0; i<list.count(); i++) // 遍历该列表
{
QDomNode node = list.at(i);
if(node.isElement())
{
qDebug() << " " << qPrintable(node.toElement().tagName())
<< qPrintable(node.toElement().text());
if(nodeName.operator ==(node.toElement().tagName()))
{
result = node.toElement().text();
break;
}
}
}
}
n = n.nextSibling(); // 下一个兄弟节点
}
return result;
}