#include <QtXml>
private:
const QString CONFIG_PATH = "./config.xml";
const QString UDP_STR = "udp";
const QString TCP_STR = "tcp";
const QString SQL_STR = "sql";
const QString PACK_STR = "package";
const QString MULT_IP = "multicastIp";
const QString PORT = "port";
const QString LOCAL_IP = "localIp";
const QString LOCAL_PORT = "localPort";
const QString dbIp = "dbIp";
const QString userName="userName";
const QString Password="Password";
const QString dbName="dbName";
QByteArray _onePackage; //一个整包数据
QUdpSocket _multicastUdp;
QHostAddress localIp;
uint localPort;
uint _port;
QHostAddress _multIp;
QDomElement _packElement;
QString dbip,username,password,dbname;
void NetworkRcv::_initConfig()
{
QDomDocument doc;
QDomElement root;
QFile file(CONFIG_PATH);
if(file.open(QFile::ReadOnly)){
if(doc.setContent(&file)){
root = doc.documentElement();
}
file.close();
}
for(int i=0;i<root.childNodes().size();i++){
QDomElement secondElement = root.childNodes().at(i).toElement();
if(secondElement.tagName() == UDP_STR)
{
_multIp = QHostAddress(secondElement.attribute(MULT_IP, ""));//组网地址
_port = secondElement.attribute(PORT, "").toInt();//组网端口
localIp = QHostAddress(secondElement.attribute(LOCAL_IP, ""));
localPort = secondElement.attribute(LOCAL_PORT, "").toInt();
}
else if(secondElement.tagName()== SQL_STR)
{
dbip = secondElement.attribute(dbIp, "");
username= secondElement.attribute(userName, "");
password= secondElement.attribute(Password, "");
dbname =secondElement.attribute(dbName, "");
}
}
}