XML文件加载QT不起作用

时间:2015-07-01 15:00:47

标签: xml qt load

这个xml读取根本不起作用,我不明白为什么。我不确定它是否正确创建了用户对象,但无论如何我无法在数据库加载后登录任何帐户。

每当我在不关闭应用程序的情况下注册用户帐户时,我都可以登录,因此我认为这不是登录问题。 XML保存工作正常。

我的数据库是SmartUtente *对象的列表。 SmartUtente对象只是一个用户*。

void Database::load(string p){
cout<<"Caricamento in corso..."<<endl;
try{
    if(p.empty()) return;
    if(!p.empty()) clean();
    QDomDocument doc("dbLinkedin");
    QFile file(QString::fromStdString(path));
    if (!file.open(QIODevice::ReadOnly | QIODevice::WriteOnly)){
        cout<<"Errore: permessi insufficienti \n";
        throw Eccezioni::BadPermission();
    }
    int n = 0;
    El users = doc.firstChildElement("users").firstChildElement("user");
    while(!users.isNull()){
        El pointer;
        Utente * s;
        if(users.attributeNode("type").value() == "basic"){
            s= new UtenteBasic();
        }
        else if(users.attributeNode("type").value() == "business"){
            s= new UtenteBusiness();
        }
        else if(users.attributeNode("type").value() == "executive"){
            s= new UtenteBusiness();
        }
        s->setName((users.firstChildElement("name").text()).toStdString());
        s->setSurname((users.firstChildElement("surname").text()).toStdString());
        s->setUsername((users.firstChildElement("username").text()).toStdString());
        s->setPassword((users.firstChildElement("password").text()).toStdString());
        s->setSesso((users.firstChildElement("genre").text()).toStdString());
        s->setCity((users.firstChildElement("city").text()).toStdString());
        s->setEmail((users.firstChildElement("email").text()).toStdString());
        pointer= users.firstChildElement("qualifications").firstChildElement("qualific");
        while(!pointer.isNull()){
            s->setQualification((pointer.text()).toStdString());
            pointer= pointer.nextSiblingElement("qualification");
        }
        s->setBirth((users.firstChildElement("birth").text()).toStdString());
        pointer= users.firstChildElement("contacts").firstChildElement("contact");
        while(!pointer.isNull()){
            s->setRete((pointer.text()).toStdString());
            pointer= pointer.nextSiblingElement("contact");
        }
        SmartUtente* su= new SmartUtente(s);
        db.push_back(su);
        users= users.nextSiblingElement("user");
        n++;
    }
    cout<<"Termine caricamento"<<endl;
    setPath(p);
    cout<<"Path settato"<<endl;
    file.close();
}
catch(Eccezioni::BadPermission){
    QMessageBox::information(0,"Caricamento non riuscito","E' possibile che non si disponga più dei permessi necessari per leggere il database");
    return;
}

}

1 个答案:

答案 0 :(得分:0)

解决。

缺少doc.setContent(&amp; file);