Unsolved QTableView Empty ?
-
@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.
-
@SGaist Do you mean creating a database and database table in code ?
-
Before going further, one thing is not clear... Where do you get these records from ?
-
@SGaist From a sqlite database on file...The output from that function is a QVector of QSqlRecords and I didn't really want to mess with that function but now I have the need to display the data neatly in my GUI.
-
Then why not use a QSqlTableModel ?
Or a QSqlQueryModel ?There would be no need for that vector of records.
-
@SGaist Let's say I only get passed the records and can't access the DB file myself... Obviously the function could be changed to pass the results in that format already but right now it's in the form of QtSqlRecords...
-
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.