How can I add a QSting and an int to a tableView at same time when a button is clicked?
What I want is to have the first column with names and the second column with numbers. Both items need to be added at the same row when a button is clicked.
Col 1--- Col 2---
First Name 1
Second Name 2
Third Name 3
Here is what I have which adds two strings, how can I convert the second cell to be an int?
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
model = new QStandardItemModel();
model->setRowCount(0);
ui->tableView->setModel(model);
}
MainWindow::~MainWindow()
{
delete ui;
}
void MainWindow::on_pushButton_clicked()
{
QStandardItem *userName = new QStandardItem(ui->lineEdit_Name->text());
QStandardItem *userNumber = new QStandardItem(ui->lineEdit_Number->text());
QList<QStandardItem*> row;
row <<userName << userNumber;
model->appendRow(row);
}
Thanks a lot