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
Forum Updated to NodeBB v4.3 + New Features

View data from two classes in a table

Scheduled Pinned Locked Moved Unsolved General and Desktop
2 Posts 2 Posters 275 Views 1 Watching
  • 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 19 Oct 2018, 01:22 last edited by Caio.Sousa
    #1

    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));
    
    
    }
    
    1 Reply Last reply
    0
    • S Offline
      S Offline
      SGaist
      Lifetime Qt Champion
      wrote on 19 Oct 2018, 19:04 last edited by
      #2

      Hi,

      Shouldn't you just store these informations in a database ?

      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

      1/2

      19 Oct 2018, 01:22

      • Login

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