Hey @all,

i've a problem with a subclass of a QSqlQueryModel.
After I insert data into the database (SQLITE) and refresh the model, the view is not refreshed.
Here the code of the subclass:
Qt Code:
  1. MyModel::MyModel(QObject *parent) : QSqlQueryModel(parent) {
  2. // Innitialize the model
  3. refreshModel();
  4. }
  5.  
  6. void MyModel::addRecord() {
  7. QSqlQuery query;
  8. bool ok = query.exec("INSERT INTO ......");
  9. if(!ok) {
  10. QSqlError err;
  11. err = query.lastError();
  12. qDebug() << err.text();
  13. return;
  14. }
  15. refreshModel();
  16. }
  17.  
  18. QVariant MyModel::data(const QModelIndex &index, int role) const {
  19. if(index.isValid() && role == Qt::BackgroundRole) {
  20. QPalette palette;
  21.  
  22. // Alternating row color
  23. if(index.row() % 2 == 0)
  24. return palette.color(QPalette::Active, QPalette::Base);
  25. return palette.color(QPalette::Active, QPalette::AlternateBase);
  26. }
  27. return QSqlQueryModel::data(index, role);
  28. }
  29.  
  30. void MyModel::refreshModel() {
  31. clear();
  32. QSqlQueryModel::setQuery("SELECT field1, field2 field3, ....");
  33.  
  34. // Set the Header fields
  35. // ...
  36. }
To copy to clipboard, switch view to plain text mode 

Qt Code:
  1. m_ui->tableView->setModel(myModel);
  2. m_ui->tableView->hideColumn(0);
  3. m_ui->tableView->verticalHeader()->hide();
  4. m_ui->tableView->horizontalHeader()->hide();
To copy to clipboard, switch view to plain text mode 

The program never went into "if(!ok) {". In the debugger the refreshModel() is called, but the TableView isn't refreshed.

Can anybody help?
Thanks in advance

Best Regards
NoRulez