读取XML配置

读取XML配置

#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, "");
        }
    }
}
上一篇:AttributeError: module ‘socket‘ has no attribute ‘AF_UNIX‘的一种解决方案


下一篇:[日常问题记录]华为模拟器ensp1.2版本在win10下启动virtualbox兼容性问题