View data from two classes in a table
-
wrote on 19 Oct 2018, 01:22 last edited by Caio.Sousa
Here's a way I'm using to write to a file and populate a table. It's working, however it's giving ""split"" to get the values separated.
I have the class Person with all these attributes and in the table I want to display only the name, and in another class called Room display in table the Room Type, Number and a Date.
But I do not know how I'm going to do this because I want to write the Room class data to a file other than the Person class and take that specific data in each file and display it in the table.
And I have a method of removing also that when I click delete delete the fourth and the selected Person. (I can erase the person);
In short I do not want to save the names of the variables and display giving "split" in the file ,I want to give a get in specific attributes and display for each Person and Room registered.
Example...p.getNome(),q.getRoom(),q.getRoomType().....Does anyone have any ideas ?
void menupainel::on_btnConfirmar_clicked() { Pessoa *p=new Pessoa(); QDate Mydate =ui->dateNasc->date(); QString date = Mydate.toString(); QString nome = ui->txtNome->text(); QString idade = ui->txtIdade->text(); QString sexo = ui->comboSexo->currentText(); QString rg = ui->txtRG->text(); QString email = ui->txtEmail->text(); QString cidade = ui->txtCity->text(); QString estado = ui->txtEstado->text(); QString telefone = ui->txtTelefone->text(); QString celular = ui->txtCel->text(); p->setNome(nome.toStdString()); p->setIdade(idade.toStdString()); p->setSexo(sexo.toStdString()); p->setRG(rg.toStdString()); p->setData(date.toStdString()); p->setEstado(estado.toStdString()); p->setCidade(cidade.toStdString()); p->setTelefone(telefone.toStdString()); p->setCelular(celular.toStdString()); p->setEmail(email.toStdString()); QFile file("C:\\Users\\Caio\\Documents\\testeRemover.txt"); if(!file.open(QIODevice::Append|QIODevice::Text)) return; QTextStream out(&file); out<< QString::fromStdString(p->getNome())<<"-"<< QString::fromStdString(p->getIdade())<<"-"<< QString::fromStdString(p->getSexo())<<"-"<< QString::fromStdString(p->getRG())<<"-"<< QString::fromStdString(p->getData())<<"-"<< QString::fromStdString(p->getEstado())<<"-"<< QString::fromStdString(p->getCidade())<<"-"<< QString::fromStdString(p->getTelefone())<<"-"<< QString::fromStdString(p->getCelular())<<"-"<< QString::fromStdString(p->getEmail())<<"\n"; file.close(); ui->stackedWidget->setCurrentIndex(2); } void menupainel::on_btnAtualizar_clicked() { borrar(); QFile file("C:\\Users\\Caio\\Documents\\testeRemover.txt"); if(!file.open(QIODevice::ReadOnly|QIODevice::Text)) return; QTextStream in(&file); while(!in.atEnd()){ QString line =in.readLine(); lis(line); } file.close(); } void menupainel::lis(QString linea){ QStringList A =linea.split("-"); QString Nome=A[0]; QString Id=A[1]; QString Quarto=A[2]; QString Numero=A[3]; ui->tableWidget->insertRow(ui->tableWidget->rowCount()); ui->tableWidget->setItem(ui->tableWidget->rowCount()-1,0,new QTableWidgetItem(Nome)); ui->tableWidget->setItem(ui->tableWidget->rowCount()-1,1,new QTableWidgetItem(Id)); ui->tableWidget->setItem(ui->tableWidget->rowCount()-1,2,new QTableWidgetItem(Quarto)); ui->tableWidget->setItem(ui->tableWidget->rowCount()-1,3,new QTableWidgetItem(Numero)); }
-
Hi,
Shouldn't you just store these informations in a database ?
1/2