Guest User

Untitled

a guest
Oct 22nd, 2017
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 5.34 KB | None | 0 0
  1. //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.
  2.  
  3. Legami::Legami(){
  4.     db=new Database("database.db");
  5.     utenti=db->caricautenti();
  6.     gruppi=db->caricagruppi(); // <-- ERRORE SEG FAULT PARTE DA QUI
  7.     db->popolacontatti(utenti);
  8.     db->popolagruppi(utenti,gruppi);
  9. }
  10.  
  11.  
  12. //QUESTA E' LA FUNZIONE, NON PRENDERE UN COLPO PER LA DIMENSIONE, LA PRIMA PARTE SEMPLICEMENTE SI PRENDE I DATI DEL CONTATTO ;)
  13.  
  14. void Database::popolacontatti(QVector<Account*>* utenti){ //UTENTI E' IL VETTORE CHE CREO IN CARICAUTENTI
  15.         for(QVector<Account*>::iterator it= utenti->begin(); it!= utenti->end(); it++){ //scorro tutti gli utenti
  16.             QSqlQuery query_cont;
  17.             QString utente=(*it)->getUsn();
  18.             query_cont.prepare("SELECT user_agg, tag FROM Collegamenti WHERE user= :u");
  19.             query_cont.bindValue(":u", utente);
  20.             query_cont.exec();
  21.             while(query_cont.next()){
  22.                 QString uagg= query_cont.value(0).toString();  //username del contatto
  23.                 QString tag= query_cont.value(1).toString(); //tag del contatto
  24.                 QSqlQuery subquery_cont;
  25.                 QString pwd;
  26.                 subquery_cont.prepare("SELECT password FROM Utenti WHERE username=:u");
  27.                 subquery_cont.bindValue(":u", uagg);
  28.                 subquery_cont.exec();
  29.                 while(subquery_cont.next()){
  30.                 pwd=subquery_cont.value(0).toString();
  31.                 }
  32.                 Username* username= new Username(uagg, pwd); //creo un nuovo username
  33.  
  34.                 //INFO
  35.                 QString nome;
  36.                 QString cognome;
  37.                 QDate datanascita;
  38.                 QString citta;
  39.                 QString email;
  40.                 QSqlQuery subquery_a;
  41.                 subquery_a.prepare("SELECT DISTINCT nome, cognome, datanascita, citta, email FROM Info WHERE User=:u");
  42.                 subquery_a.bindValue(":u", uagg);
  43.                 subquery_a.exec();
  44.                 while(subquery_a.next()){
  45.                     nome= subquery_a.value(0).toString();
  46.                     cognome= subquery_a.value(1).toString();
  47.                     datanascita= subquery_a.value(2).toDate();
  48.                     citta= subquery_a.value(3).toString();
  49.                     email= subquery_a.value(4).toString();
  50.                }
  51.  
  52.                 //ISTRUZIONE
  53.                 QSqlQuery subquery_b;
  54.                 QVector<Scuola*> istruzione;
  55.                 subquery_b.prepare("SELECT nomescuola, datainizio, datafine FROM Scuole WHERE User= :u");
  56.                 subquery_b.bindValue(":u", uagg);
  57.                 subquery_b.exec();
  58.                 while(subquery_b.next()){
  59.                     QString nomescuola= subquery_b.value(0).toString();
  60.                     QDate datainizio= subquery_b.value(1).toDate();
  61.                     QDate datafine= subquery_b.value(2).toDate();
  62.                     istruzione.push_back(new Scuola(nomescuola,datainizio,datafine));
  63.                 }
  64.  
  65.                 //FORMAZIONE
  66.                 QVector<Occupazione*> formazione;
  67.                 QSqlQuery subquery_c;
  68.                 subquery_c.prepare("SELECT azienda, ruolo, datainizio, datafine FROM occupazioni WHERE User= :u");
  69.                 subquery_c.bindValue(":u", uagg);
  70.                 subquery_c.exec();
  71.                 while(subquery_c.next()){
  72.                     QString azienda= subquery_c.value(0).toString();
  73.                     QString ruolo= subquery_c.value(1).toString();
  74.                     QDate datainizio= subquery_c.value(2).toDate();
  75.                     QDate datafine= subquery_c.value(3).toDate();
  76.                     formazione.push_back(new Occupazione(azienda,ruolo,datainizio,datafine));
  77.                 }
  78.  
  79.                 Info* info=new Info(nome, cognome, datanascita, citta, formazione, istruzione, email); //info uagg
  80.                 Profilo* pr=new Profilo(info);
  81.                 Contatto* contatto=new Contatto(tag, username, pr);//contatto uagg
  82.                 cout << (*it) << endl;
  83.                 (*it)->insertContatto(contatto); // <-- ERRORE IN QUESTA FUNZIONE!!!!
  84.             }
  85.         }
  86.     }
  87.  
  88. //LA FUNZIONE insertContatto E' QUESTA:
  89.  
  90. bool Account::insertContatto(Contatto* c) {
  91.             cout << collegamenti << endl;
  92.             cout << this << endl;
  93.             if(collegamenti->count()<8){ << !!!! SEG FAULT !!!!
  94.             collegamenti->push_back(c);
  95.             return true;
  96.         }
  97.      else return false;
  98.   }
  99.  
  100. //DOVE collegamenti E' DICHIARATO DEI CAMPI DELLA CLASSE User, CLASSE BASE di Account.
  101.  
  102. class User {
  103.  protected:
  104.   Username* us;
  105.   Profilo* pr;
  106.   QVector<Contatto*>* collegamenti; //dello user!
  107.   QVector<Gruppo*>* gruppi; //dello user!
  108.  public:
  109. //ETCETCETCETCETCETCETC
  110.  
  111.  
  112. //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