Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct
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 :)
You should take a look at QSqlTableModel and the examples linked in the documentation there.
Thanks, I try also the example, very cool .
But still I don't understand how to display the QsqlTableModel on a UI.
I just create a simple UI
Then I don't know how to display the tablemodel.
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();
Qt models work with views
For DB models often TableView is used.
you have to set the model from code.
Thanks to All
All solved :)