0

我有 3 个QLineEdits(比如姓名、地址和电话号码)、一个QPushButton(添加按钮)和一个QTableView.

当我在QLineEdits所有.QLineEditsQTableView

我怎样才能做到这一点?

4

1 回答 1

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);
}
于 2012-09-25T13:45:04.977 回答