Reader small image

You're reading from  Qt 6 C++ GUI Programming Cookbook - Third Edition

Product typeBook
Published inApr 2024
PublisherPackt
ISBN-139781805122630
Edition3rd Edition
Right arrow
Author (1)
Lee Zhi Eng
Lee Zhi Eng
author image
Lee Zhi Eng

Lee Zhi Eng is a self-taught programmer who worked as an artist and programmer at several game studios before becoming a part-time lecturer for 2 years at a university, teaching game development subjects related to Unity and Unreal Engine. He has not only taken part in various projects related to games, interactive apps, and virtual reality but has also participated in multiple projects that are more oriented toward software and system development. When he is not writing code, he enjoys traveling, photography, and exploring new technologies.
Read more about Lee Zhi Eng

Right arrow

Writing basic SQL queries

In the previous example, we wrote our very first SQL query, which involves the SELECT statement. This time, we will learn how to use some other SQL statements, such as INSERT, UPDATE, and DELETE.

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:
Figure 12.12 – Modify the UI to this

Figure 12.12 – Modify the UI to this

  1. Open mainwindow.h and add the following variables under the private inheritance:
    private:
         Ui::MainWindow *ui;
         QSqlDatabase db;
         bool connected;
         int currentID;
  2. Open mainwindow...
lock icon
The rest of the page is locked
Previous PageNext Page
You have been reading a chapter from
Qt 6 C++ GUI Programming Cookbook - Third Edition
Published in: Apr 2024Publisher: PacktISBN-13: 9781805122630

Author (1)

author image
Lee Zhi Eng

Lee Zhi Eng is a self-taught programmer who worked as an artist and programmer at several game studios before becoming a part-time lecturer for 2 years at a university, teaching game development subjects related to Unity and Unreal Engine. He has not only taken part in various projects related to games, interactive apps, and virtual reality but has also participated in multiple projects that are more oriented toward software and system development. When he is not writing code, he enjoys traveling, photography, and exploring new technologies.
Read more about Lee Zhi Eng