I have a tableview on a qmlfile, I'm trying to set the model from c++.

The model I'm using is QSqlTableModel, if a create a new tableview and set the model from c++ it seems to work, but when I pass the model to the model property in the qmlfile it doesn't work and I can't figure out why...

the c++ model code is:
Qt Code:
  1. QSqlTableModel * SqlEventModel::getTableData(QString tableName, QTableView *item){
  2.  
  3. const QString queryStr = "SELECT sql FROM sqlite_master WHERE tbl_name = '" + tableName +"' AND type = 'table'" ;
  4. QSqlQuery query(queryStr);
  5. if (!query.exec())
  6. qFatal("Query failed");
  7.  
  8.  
  9. QSqlDatabase db = QSqlDatabase::database(":memory:");
  10.  
  11. QSqlTableModel *model = new QSqlTableModel(item, db);
  12. model->setTable(tableName);
  13. model->setEditStrategy(QSqlTableModel::OnManualSubmit);
  14. model->select();
  15.  
  16.  
  17. int i=0;
  18. while (query.next()){
  19. model->setHeaderData(i, Qt::Vertical, query.value(i).toString());
  20. i++;
  21. }
  22.  
  23. return model;
  24.  
  25. }
To copy to clipboard, switch view to plain text mode 
that returns a model which works if within c++ I create a tableview and assign the model but when I do this:

Qt Code:
  1. TableView{
  2. id: table;
  3. width: parent.width -100
  4. height: parent.height -200
  5. anchors.horizontalCenter: parent.horizontalCenter
  6. anchors.top: parent.top
  7. anchors.topMargin: 90
  8. model: SqlEventModel.getTableData(GData.tName,table)
  9. }
To copy to clipboard, switch view to plain text mode 
it doesn't work, it just shows an empty table even though when I debug the tableview model is not empty...

if I add:

Qt Code:
  1. QTableView *view = new QTableView();
  2. view->setModel(model);
  3. view->show();
To copy to clipboard, switch view to plain text mode 

just before the return on the c++ function I get a new window with a table which properly displays the table... I tried adding columns with the same rolename that I give in c++ and they won't populate either.... here's a screenshot of both tables

http://i.stack.imgur.com/gGzhu.png

posted a