Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //L'ERRORE PARTE DA QUI. QUESTO E' IL COSTRUTTORE DI LEGAMI, IN CUI SI CREA UN NUOVO DATABASE, E SI INVOCANO LE FUNZIONI SUCCESSIVE. LE PRIME DUE CARICANO SEMPLICEMENTE I DATI, MENTRE LE ALTRE DUE "COLLEGANO" CONTATTI E GRUPPI. IL PROBLEMA STA IN CARICA UTENTI, CHE E' IL CORRISPETTIVO DEL TUO fillUsers DI board.h SE NON ERRO! db E' UN PUNTATORE A DATABASE.
- Legami::Legami(){
- db=new Database("database.db");
- utenti=db->caricautenti();
- gruppi=db->caricagruppi(); // <-- ERRORE SEG FAULT PARTE DA QUI
- db->popolacontatti(utenti);
- db->popolagruppi(utenti,gruppi);
- }
- //QUESTA E' LA FUNZIONE, NON PRENDERE UN COLPO PER LA DIMENSIONE, LA PRIMA PARTE SEMPLICEMENTE SI PRENDE I DATI DEL CONTATTO ;)
- void Database::popolacontatti(QVector<Account*>* utenti){ //UTENTI E' IL VETTORE CHE CREO IN CARICAUTENTI
- for(QVector<Account*>::iterator it= utenti->begin(); it!= utenti->end(); it++){ //scorro tutti gli utenti
- QSqlQuery query_cont;
- QString utente=(*it)->getUsn();
- query_cont.prepare("SELECT user_agg, tag FROM Collegamenti WHERE user= :u");
- query_cont.bindValue(":u", utente);
- query_cont.exec();
- while(query_cont.next()){
- QString uagg= query_cont.value(0).toString(); //username del contatto
- QString tag= query_cont.value(1).toString(); //tag del contatto
- QSqlQuery subquery_cont;
- QString pwd;
- subquery_cont.prepare("SELECT password FROM Utenti WHERE username=:u");
- subquery_cont.bindValue(":u", uagg);
- subquery_cont.exec();
- while(subquery_cont.next()){
- pwd=subquery_cont.value(0).toString();
- }
- Username* username= new Username(uagg, pwd); //creo un nuovo username
- //INFO
- QString nome;
- QString cognome;
- QDate datanascita;
- QString citta;
- QString email;
- QSqlQuery subquery_a;
- subquery_a.prepare("SELECT DISTINCT nome, cognome, datanascita, citta, email FROM Info WHERE User=:u");
- subquery_a.bindValue(":u", uagg);
- subquery_a.exec();
- while(subquery_a.next()){
- nome= subquery_a.value(0).toString();
- cognome= subquery_a.value(1).toString();
- datanascita= subquery_a.value(2).toDate();
- citta= subquery_a.value(3).toString();
- email= subquery_a.value(4).toString();
- }
- //ISTRUZIONE
- QSqlQuery subquery_b;
- QVector<Scuola*> istruzione;
- subquery_b.prepare("SELECT nomescuola, datainizio, datafine FROM Scuole WHERE User= :u");
- subquery_b.bindValue(":u", uagg);
- subquery_b.exec();
- while(subquery_b.next()){
- QString nomescuola= subquery_b.value(0).toString();
- QDate datainizio= subquery_b.value(1).toDate();
- QDate datafine= subquery_b.value(2).toDate();
- istruzione.push_back(new Scuola(nomescuola,datainizio,datafine));
- }
- //FORMAZIONE
- QVector<Occupazione*> formazione;
- QSqlQuery subquery_c;
- subquery_c.prepare("SELECT azienda, ruolo, datainizio, datafine FROM occupazioni WHERE User= :u");
- subquery_c.bindValue(":u", uagg);
- subquery_c.exec();
- while(subquery_c.next()){
- QString azienda= subquery_c.value(0).toString();
- QString ruolo= subquery_c.value(1).toString();
- QDate datainizio= subquery_c.value(2).toDate();
- QDate datafine= subquery_c.value(3).toDate();
- formazione.push_back(new Occupazione(azienda,ruolo,datainizio,datafine));
- }
- Info* info=new Info(nome, cognome, datanascita, citta, formazione, istruzione, email); //info uagg
- Profilo* pr=new Profilo(info);
- Contatto* contatto=new Contatto(tag, username, pr);//contatto uagg
- cout << (*it) << endl;
- (*it)->insertContatto(contatto); // <-- ERRORE IN QUESTA FUNZIONE!!!!
- }
- }
- }
- //LA FUNZIONE insertContatto E' QUESTA:
- bool Account::insertContatto(Contatto* c) {
- cout << collegamenti << endl;
- cout << this << endl;
- if(collegamenti->count()<8){ << !!!! SEG FAULT !!!!
- collegamenti->push_back(c);
- return true;
- }
- else return false;
- }
- //DOVE collegamenti E' DICHIARATO DEI CAMPI DELLA CLASSE User, CLASSE BASE di Account.
- class User {
- protected:
- Username* us;
- Profilo* pr;
- QVector<Contatto*>* collegamenti; //dello user!
- QVector<Gruppo*>* gruppi; //dello user!
- public:
- //ETCETCETCETCETCETCETC
- //IN PRATICA NON RIESCE AD ACCEDERE A COLLEGAMENTI :( COME VEDI HO STAMPATO L'INDIRIZZO DI MEMORIA DELL'ACCOUNT SIA IN popolacontatti (con (*it)) CHE IN insertContatto (con this). L'INDIRIZZO E' LO STESSO, NON SO SE SIA UTILE SAPERLO MA COSI' SONO ALMENO SICURA DI INVOCARE LA FUNZIONE SULL'OGGETTO GIUSTO, O SBAGLIO? (PROBABILE)
Add Comment
Please, Sign In to add comment