Aleksey Shi Aleksey Shi - 10 months ago 45
SQL Question

qtsql-querymodel-editablesqlmodel: why need refresh?

I study for example
I have one question, why after query UPDATE statement, model is cleared on view (view is empty) and shows data after refresh calling SELECT statement?
I think so, there's no SELECT running and model doesn't have to change.

Answer Source

The model is directly displaying the result of a SELECT query, so it displayed the state of the database at the time of querying.

The code that updates the database uses operations that do not directly affect the model's internal data (the cached result of the previous SELECT query), so there is no change as far as the view is concerned.

Applying the SELECT query again in refresh() updates the model's knowledge about that database state and thus results in new data being available in the view.

The "clearing" is caused by the call to clear() in setData(). Not sure why it is there, I don't think it is necessary.