Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. View data from two classes in a table - OO
QtWS25 Last Chance

View data from two classes in a table - OO

Scheduled Pinned Locked Moved Unsolved General and Desktop
2 Posts 2 Posters 247 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • C Offline
    C Offline
    Caio.Sousa
    wrote on last edited by
    #1

    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));
    
    
    }
    
    
    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

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

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      0

      • Login

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • Users
      • Groups
      • Search
      • Get Qt Extensions
      • Unsolved