QTableView first time use
-
Trying to diplay a SQLite table into my application was a struggle but I got there. I can even edit every entry in real time.
The only thing that does not seem possible is to add a new entry in this form, or to filter columns from displaying.
QSqlDatabase mydb=QSqlDatabase::addDatabase("QSQLITE"); mydb.setDatabaseName("mydatabase.db"); QSqlTableModel *modal = new QSqlTableModel; modal->setTable("MyFirstTable"); modal->select(); ui->tableView_MyFirstTableView->setModel(modal);
Another problem I am having in my learning curve is that I wouold like to seperate this function into it's own class (call it MyTableView()) so I can call it taking the table as a variable and the ui->window as a output:
MyTableView(MyfirstTable,MyFirstTableView)
So I created a new Class (cpp/h) and cut my code in there but that crashed the build.
-
@Seabird said in QTableView first time use:
The only thing that does not seem possible is to add a new entry in this form
You will need to add something to the
QTableView
, or a separate widget, for "Add new Row". The table view itself only has a way to edit existing rows, or to delete them if you add e.g. a "Delete" button in a column against each row, or a checkbox against each one and a "Delete" all checked rows button.or to filter columns from displaying
QTableView
allows you hide individual columns if you wish. AQAbstractProxyModel
interposed between your model table and the table view can also be used for e.g. hiding either columns or rows. The convenience proxy modelQSortFilterProxyModel
builds on that to offer both/either sorting and filtering, but note that is to sort/filter rows, not columns.So I created a new Class (cpp/h) and cut my code in there but that crashed the build.
Nobody can answer that without knowing the code and where it crashed.