QTableView Empty ?
-
@R-P-H said in QTableView Empty ?:
@mrjj No there is no database...I get given the table of results in "records" which have already been populated from a previous data pull.
I just want to easily display them in a table without manually looping through fields...
Do I need to initialise a dummy database or something ?
Hi,
If you don't have any database then why are you using a SQL model ?
Before going further, do you want to store your data in a database ? Or just show them in a tabular fashion ?
-
@SGaist Mainly I just want to display it in a tabular fashion but without the work involved in looping through each QSqlRecord and corresponding field.
Considering the data is stored in QSqlRecords I thought using QTableView would be the easiest way to achieve that...
-
You still need a valid database to insert your records in.
You can use the SQLite plugin for that and the in memory database if you don't want to store in on disk.
Note that you still have to create the table before putting something in it.
-
Before going further, one thing is not clear... Where do you get these records from ?
-
Then why not use a QSqlTableModel ?
Or a QSqlQueryModel ?There would be no need for that vector of records.
-
So you can either do as suggested and create that minimal database with the table needed to show your data or use a QStandardItemModel where you put the content of all these records.
-
@SGaist For QStandardModel I don't see a way to directly make use of my QtSqlRecords, does that mean I have to loop manually through the fields ? Would it still be shown in QTableView ?
For making a minimal database do I need to set a database name?
I will try to implement the other model on the actual dB as well....
-
Yes you do, or you can make your own custom QAbstractTableModel that will return the content of your vector of records.
Yes you do. However you can use an in-memory database if you don't want to have another database in a file.