Yep, that's the correct view

Well, I have a clicked() signal attached to a pushbutton, so I had this code in my slot for that signal and it displayed the tableview fine. I thought it would be a better design approach to have this code in the constuctor instead (but I could be wrong), so now, I don't know what to do in my slot to get the tableview to display.

Here is what my slot previously looked like (identical to the constructor) -- my question is if I put this in the constuctor instead of the slot, how do I get the tableview to display?

Qt Code:
  1. void MainWindow::on_AdminPB_clicked()
  2. {
  3. //*******************************************************
  4. //* Retrieve data from the USER table for managing... *
  5. //*******************************************************
  6. usertablemodel = new QSqlTableModel(this);
  7.  
  8. usertablemodel->setTable ("user");
  9. usertablemodel->sort (0, Qt::AscendingOrder);
  10.  
  11. usertablemodel->setEditStrategy (QSqlTableModel::OnManualSubmit);
  12. usertablemodel->select ();
  13.  
  14. usertablemodel->setHeaderData (0, Qt::Horizontal,
  15. QObject::tr("Username"));
  16. usertablemodel->setHeaderData (1, Qt::Horizontal,
  17. QObject::tr("Password"));
  18. usertablemodel->setHeaderData (2, Qt::Horizontal,
  19. QObject::tr("Full Name"));
  20. usertablemodel->setHeaderData (3, Qt::Horizontal,
  21. QObject::tr("Status"));
  22. usertablemodel->setHeaderData (4, Qt::Horizontal,
  23. QObject::tr("Access Level"));
  24. usertablemodel->setHeaderData (5, Qt::Horizontal,
  25. QObject::tr("User Name"));
  26. usertablemodel->setHeaderData (6, Qt::Horizontal,
  27. QObject::tr("Activity Date"));
  28.  
  29. ui->ManageUsersTV->setModel (usertablemodel);
  30. ui->ManageUsersTV->resizeColumnsToContents ();
  31.  
  32. ui->ManageUsersTV->setEditTriggers (QAbstractItemView::AnyKeyPressed |
  33. QAbstractItemView::DoubleClicked);
  34.  
  35. }
To copy to clipboard, switch view to plain text mode