[solved]My SqlModel and refresh view
I have a model - yes is not very elegant but I need class like this:
Code:
{
public:
/*
there are all methods needed by model like
rowCount, columnCount, data ...
*/
bool insert( const QSqlRecord& rec );
protected:
}
All methods are redirect to model like:
Code:
int MySqlModel
::rowCount(const QModelIndex &parent
) const {
return model->rowCount();
}
I'm making insert to table by method which looks like that:
Code:
bool MySqlModel::insert( const QSqlRecord& rec )
{
query->prepare( insertQuery );
if( query->exec() )
{
// here I want to refresh a view
// I remove this -> emit dataChanged( QModelIndex(), QModelIndex() ); // nothing happens :(
// this methods resolved my issue
endInsertRows();
}
}
How I should update view? I create view like this:
Code:
view->setModel( model ); // model it is MySqlModel and data are in view after this operation - view is a standard QTableView
Solution I describe in listening with insert method.