0
int main(int argc, char *argv[])
{
   QApplication a(argc, argv);

After making connection, I tried this code , but it doesn't display any data

   QSqlTableModel *model=new QSqlTableModel; 
   model->setTable("tamp");
   model->select();
   QTableView *view = new QTableView;
   view->setModel(model);
   view->show();
   db.close();
   return a.exec()
}
Katrin
  • 5
  • 2
  • 1
    The code that you show us would crash (since you don't allocate a model), so it's hard to say anything at all. – E4z9 Dec 12 '16 at 11:10
  • Possible duplicate of [Qt's model/view architecture](http://stackoverflow.com/questions/41078500/qts-model-view-architecture) – Kevin Krammer Dec 12 '16 at 11:38
  • You should not be calling `db.close()` after `view->show()`. `QSqlTableModel` requires the database connection to be open while it is being used (e.g. for editing to work). – Mike Dec 12 '16 at 12:36

0 Answers0