Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- mainwindow.cpp
- MainWindow::MainWindow(QWidget *parent) :
- QMainWindow(parent),
- ui(new Ui::MainWindow)
- {
- ui->setupUi(this);
- QStandardItemModel *model = new QStandardItemModel(0,5,this); //2 Rows and 3 Columns
- model->setHorizontalHeaderItem(0, new QStandardItem(QString("Company Name")));
- model->setHorizontalHeaderItem(1, new QStandardItem(QString("Phone")));
- model->setHorizontalHeaderItem(2, new QStandardItem(QString("Email")));
- model->setHorizontalHeaderItem(3, new QStandardItem(QString("Contact person")));
- model->setHorizontalHeaderItem(4, new QStandardItem(QString("Phone")));
- //tablemodel
- this->tablemodel = model;
- ui->tableView->setModel(model);
- }
- //accesor method for the table model
- QStandardItemModel* MainWindow::tm(){
- return this->tablemodel;
- }
- clientInfo.cpp
- void ClientInfo::on_buttonBox_accepted()
- {
- //get the user data
- //company details
- string companyName = ui->companyName->text().toStdString();
- string companyPhone = ui->companyPhone->text().toStdString();
- //now disply this to the table
- MainWindow *mw = new MainWindow();
- //get the model using accessor method from the main window widget
- QStandardItemModel *model = mw->tm();
- //fill in the data
- model->setItem(0,0,new QStandardItem(QString(companyName)));
- model->setItem(0,1,new QStandardItem(QString(companyPhone)));
- //when i click okay, this data is never reflected on the main window!!
- //what am i missing?
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement