Hi,

I am getting "Unable to find table" when I execute QSqlTableModel.select(). Strange enough I don't get an error when querying the same table of the QSqlTableModel. Here is the code:

Qt Code:
  1. //Test query
  2. QSqlQuery *mquery = new QSqlQuery(db);
  3. if (!mquery->exec("SELECT * FROM country"))
  4. {
  5. qDebug() << "Query:" << mquery->lastError().driverText();
  6. }
  7. while (mquery->isValid())
  8. {
  9.  
  10. mquery->next();
  11. }
  12.  
  13. ui->setupUi(this);
  14. m_mainmodel = new maintModel(this,db);
  15. m_mainmodel->setTable("country");
  16. m_mainmodel->setEditStrategy(QSqlTableModel::OnManualSubmit);
  17. if (m_mainmodel->select())
  18. {
  19. m_mainmodel->loadStatus();
  20. m_mainmodel->setHeaderData(0, Qt::Horizontal, tr("Name"));
  21. //m_mainmodel->setDisplayColumn("CNTY_NAM",tr("Countries"));
  22. ui->ListView1->setModel(m_mainmodel);
  23. }
  24. else
  25. {
  26. // It cannot find the table!!!!!
  27. qDebug() << m_mainmodel->lastError().driverText();
  28. }
To copy to clipboard, switch view to plain text mode 

In the code the test query works but not the model select.

The constructor of maintModel is:

Qt Code:
  1. maintModel::maintModel(QObject *parent, QSqlDatabase)
  2. :QSqlTableModel(parent)
  3. {
  4.  
  5. }
To copy to clipboard, switch view to plain text mode 

Any idea why?

Thanks,
Carlos.