What to subclass?
-
Hi,
currently I'm subclassing
QSqlQueryModel
to get an editable model (data comes from SQLite DB).
I select the "base"-data with aQSqlQuery
at the moment, but now I need to insert columns manually, because I want to show data, which is calculated on runtime (not in DB).
Somewhere I've read that I need to subclassQAbstractItemModel
orQAbstractTableModel
for this. But I think, I'm losing the Query functionality then, dont I?The next thing I'm thinking of, is using some widgets like
QComboBox
inside the model to select between given values, when editing.So basically:
- Model shows data from DB (multiple tables), currently by executing a
QSqlQuery
- user clicks an editable cell (where "editable" flag was set), if cell contains digits (int type) -> ComboBox with valid numbers is shown,
- user can select value, on "enter" or something like that, the comboBox value is written to the db / model,
- the ComboBox disappears afterwards and the new value is shown inside the model.
How to insert these values to my db, when I dont have queries anymore?
I dont know if all these features are possible by sublassing one given Model-class or how else I can implement this.
Any help or code examples appreciated :)
EDIT:
The view is aQTableView
(tables are joined). I guess I have to change the view as well (to use comboBoxes for editing)?! - Model shows data from DB (multiple tables), currently by executing a
-
@pl45m4 said in What to subclass?:
when I dont have queries anymore?
What prohibits you to use a QSqlQuery within your custom class derived from QAbstractItemModel?
-
I assumed that
QAbstractItemModel
provides nosetQuery()
. So I have to write my own function to execute aQSqlQuery
? -
-
Is there any other way to get data from SQLite database with Qt except queries?
Implementing the functionality to use SQL queries is not what I what to do. It sounds very complicated or is it not that hard? -
I don't see what's complicated executing a QSqlQuery and fetching the data. Especially compared to the idea to parse the data somehow from a sqlite file...
-
@christian-ehrlicher said in What to subclass?:
I don't see what's complicated executing a QSqlQuery and fetching the data.
Because I cannot add the calculated data to my model, if I use a
QSqlTableModel
subclass, so I thought I can subclassQAbstractTableModel
orQAbstractItemModel
butsetQuery()
is implemented first inQSqlTableModel
.EDIT:
You mean executing the query to get the data from DB, without setting the data to the model directly?
So I can execute the query to get my "base"-data, then calculate the missing cols and then set the data to the model? -
@pl45m4 said in What to subclass?:
You mean executing the query to get the data from DB, without setting the data to the model directly?
Yes
-
@christian-ehrlicher said in What to subclass?:
Especially compared to the idea to parse the data somehow from a sqlite file
Where I have said that? :)
I never had the idea to "parse" the sqlite file directly.I will try to get the data with a query first and see what I can do with it :)
(I guessQSqlResult
is the key?!)