Advertisement
oquidave

Qt tableview

Sep 7th, 2012
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.49 KB | None | 0 0
  1. mainwindow.cpp
  2.  
  3. MainWindow::MainWindow(QWidget *parent) :
  4.     QMainWindow(parent),
  5.     ui(new Ui::MainWindow)
  6. {
  7.     ui->setupUi(this);
  8.     QStandardItemModel *model = new QStandardItemModel(0,5,this); //2 Rows and 3 Columns
  9.     model->setHorizontalHeaderItem(0, new QStandardItem(QString("Company Name")));
  10.     model->setHorizontalHeaderItem(1, new QStandardItem(QString("Phone")));
  11.     model->setHorizontalHeaderItem(2, new QStandardItem(QString("Email")));
  12.     model->setHorizontalHeaderItem(3, new QStandardItem(QString("Contact person")));
  13.     model->setHorizontalHeaderItem(4, new QStandardItem(QString("Phone")));
  14.  
  15.     //tablemodel
  16.     this->tablemodel = model;
  17.     ui->tableView->setModel(model);
  18. }
  19.  
  20. //accesor method for the table model
  21. QStandardItemModel* MainWindow::tm(){
  22.     return this->tablemodel;
  23. }
  24.  
  25. clientInfo.cpp
  26.  
  27. void ClientInfo::on_buttonBox_accepted()
  28. {
  29.  
  30.     //get the user data
  31.  
  32.     //company details
  33.     string companyName = ui->companyName->text().toStdString();
  34.     string companyPhone = ui->companyPhone->text().toStdString();
  35.  
  36.     //now disply this to the table
  37.     MainWindow *mw = new MainWindow();
  38.  
  39. //get the model using accessor method from the main window widget
  40.     QStandardItemModel *model = mw->tm();
  41. //fill in the data
  42.     model->setItem(0,0,new QStandardItem(QString(companyName)));
  43. model->setItem(0,1,new QStandardItem(QString(companyPhone)));
  44.  
  45. //when i click okay, this data is never reflected on the main window!!
  46. //what am i missing?
  47.  
  48. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement