Ok here is the deal, I have the following code for opening up a database, connecting it to model, which then displays its contents on a view:

Qt Code:
  1. mainwindow::mainwindow(QWidget *parent)
  2. : QMainWindow(parent), ui(new Ui::mainwindowClass)
  3. {
  4. //This sets up the UI
  5. ui->setupUi(this);
  6. model = new QSqlTableModel(this);
  7. //This pretty much says that the database will be of SQLite type, and opens it up from a given path
  8. QSqlDatabase db = QSqlDatabase::addDatabase("QSQLITE");
  9. db.setDatabaseName("/Users/k12yp70n/Desktop/test");
  10.  
  11. //This "if" shows up a messagebox in case the program cannot load a given database
  12. if (!db.open()) {
  13. QMessageBox::warning(0, qApp->tr("Cannot open database"),
  14. qApp->tr("Unable to establish a database connection.\n"
  15. "This program requires a database to operate. Please contact "
  16. "the developer of this software for more information on "
  17. "how to solve this problem.\n\n"), QMessageBox::Ok);
  18.  
  19. }
  20.  
  21. //Note: "medadmin" is the name of the table in the SQLite3 database
  22. model->setTable ("medadmin");
  23. model->select();
  24.  
  25. //The following lines edit a couple of parameters in the table view "View" and bind it to the model
  26. ui->View->setWindowTitle ("Patients List");
  27. ui->View->setModel (model);
  28. ui->View->setSelectionBehavior (QAbstractItemView::SelectRows);
  29. ui->View->resizeColumnsToContents();
  30. ui->View->setSelectionMode (QTableView::SingleSelection);
  31. ui->View->setVisible (true);
  32. ui->View->setColumnHidden(0, true);
  33. ui->View->showGrid();
  34. setting_up_toolbar_menus();
  35. }
To copy to clipboard, switch view to plain text mode 

The problem is the view simply shows up blank! Since I do not get any errors related to the database, I am assuming that the problem lies either on the model, on the view, or both.

But I have no idea on how to solve it,

Can anyone help me please?

Any help with be largely appreciated (some code samples would also be nice by the way)

Thanks in advance