Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

View data from two classes in a table - OO



  • Hi there are a lot of data saved in a file and displaying them in a table.

    In case you are saving a varial in a class and giving a get in class it is writing in the file "Name-Age-Number ..."

    To this is giving a split and playing in the table. But I want to display for example 1 data of a class and other data of another class of different files.

    For example: Make a list of people with name, age, and Sort by Type of person, and register a room with Number and Floor of a Room class. Show class name Person, Room Number and Room Floor for example.

    Here is my current code:

    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));
    
    
    }
    
    

  • Lifetime Qt Champion

    Hi,

    Isn't that the same question as in this thread ?


Log in to reply