Hi guys, im rather new to Qt and im following a book : Foudations of Qt Development. Im trying to use the QTableView to display data, but it doesnt seem to work, it only displays a empty viewer.

This is my constructor:
Qt Code:
  1. MainDialog::MainDialog(QWidget *parent)
  2. : QDialog(parent), ui(new Ui::MainDialog)
  3. {
  4. // ui->setupUi(this);
  5. QTableView *table = new QTableView;
  6.  
  7. QStandardItemModel model(5, 2);
  8. for (int row = 0; row < 5; ++row){
  9. for (int col = 0; col < 2; ++col){
  10. QStandardItem *item = new QStandardItem(QString("Row:%1, Column:%2").arg(row).arg(col));
  11.  
  12. if (col == 0){
  13. for (int i = 0; i < 3; ++i){
  14. item->appendRow(new QStandardItem( QString("Item %1").arg(i)));
  15. }
  16. }
  17.  
  18. model.setItem(row, col, item);
  19. }
  20. }
  21.  
  22. table->setModel(&model);
  23. table->show();
  24.  
  25. QHBoxLayout *layout = new QHBoxLayout;
  26. layout->addWidget(table);
  27. setLayout(layout);
  28. }
To copy to clipboard, switch view to plain text mode 

Please be forgiving with your words as im really new thanks