example of Qt dektop SQL
-
Hi, I'm trying to understand how I can show/manipulate a DB table with QT, i will like to by pointed to some example.
Just to understand I'm use to program in Visual Studio and connect to various SQL, create form with fields and grid . I was able to connect to my server (MariaDB) and do sone basic command , now I will like to replicate what I usually do in VS , like create a window with a grid that show the data from a query.
I searched on the forum but I just find pice of code and is difficult to put all together, so if any one can point me to an example it will be wonderful :)
Thanks -
You should take a look at QSqlTableModel and the examples linked in the documentation there.
-
@saulos The link provided by @Christian-Ehrlicher shows how:
QSqlTableModel *model = new QSqlTableModel(parentObject, database); model->setTable("employee"); model->setEditStrategy(QSqlTableModel::OnManualSubmit); model->select(); model->setHeaderData(0, Qt::Horizontal, tr("Name")); model->setHeaderData(1, Qt::Horizontal, tr("Salary")); QTableView *view = new QTableView; view->setModel(model); view->hideColumn(0); // don't show the ID view->show();
-
Hi
Qt models work with views
For DB models often TableView is used.
https://doc.qt.io/qt-5/model-view-programming.htmlyou have to set the model from code.