How to do it...

Let's create a simple program that demonstrates basic SQL query commands by following these steps:

  1. We can use our previous project files, but there are a couple of things we need to change. Open mainwindow.ui and replace the labels for Name and Age with line-edit widgets. Then, add three buttons to the canvas and call them UPDATE, INSERT, and DELETE:
  1. Open mainwindow.h and add the following variables under the private inheritance:
private:    Ui::MainWindow *ui;    QSqlDatabase db;    bool connected;    int currentID;
  1. Open mainwindow.cpp and go to the class constructor. It is still pretty much the same as the previous example, except ...

Get Qt5 C++ GUI Programming Cookbook - Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.