0

I have 3 QLineEdits (say Name, Address & Phone No.), a QPushButton (Add button) and a QTableView.

When I have entered text in all the QLineEdits, and if I click the Add button, all 3 texts of the QLineEdits should be added in the first row of the QTableView.

How can I do this?

Angie Quijano
  • 4,167
  • 3
  • 25
  • 30
New Moon
  • 787
  • 6
  • 21
  • 35
  • I don't understand if you want to attache your 3 `QLineEdit`'s to a row on `QTableView`, or you want to add the content of `QLineEdit`'s to the first row of `QTableView`. – SIFE Sep 25 '12 at 14:02
  • I want to add only the contents of the 3 QLineEdit to the first row of the QTableView. – New Moon Sep 25 '12 at 14:36

1 Answers1

1
...
QStandardItemModel *model = new QStandardItemModel();
model->setRowCount(3);

yourTableView->setModel(model);

connect(yourBtn, SIGNAL(clicked()), this, SLOT(addData()));
...

void YourClass::addData()
{
    QStandardItem *nameItem = new QStandardItem(nameEdit->text());
    QStandardItem *addressItem = new QStandardItem(addressEdit->text());
    QStandardItem *phoneItem = new QStandardItem(phoneEdit->text());

    QList<QStandardItem*> row;
    row << nameItem << addressItem << phoneItem;

    model->appendRow(row);
}
hank
  • 9,553
  • 3
  • 35
  • 50
  • Thanks a lot it Works fine. But the Thing is if suppose am adding another **QPushButton** (eg. MODIFY). Now **if i click on any particular row of the QTableView the items in the row** should again be placed in their **QLineEdit's**. this is just for modifying the row again **without double clicking on each cell of the QTableView**. How can do this. kindly help. – New Moon Sep 25 '12 at 14:52