Book Image

Qt5 C++ GUI Programming Cookbook

By : Lee Zhi Eng
Book Image

Qt5 C++ GUI Programming Cookbook

By: Lee Zhi Eng

Overview of this book

With the advancement of computer technology, the software market is exploding with tons of software choices for the user, making their expectations higher in terms of functionality and the look and feel of the application. Therefore, improving the visual quality of your application is vital in order to overcome the market competition and stand out from the crowd. This book will teach you how to develop functional and appealing software using Qt5 through multiple projects that are interesting and fun. This book covers a variety of topics such as look-and-feel customization, GUI animation, graphics rendering, implementing Google Maps, and more. You will learn tons of useful information, and enjoy the process of working on the creative projects provided in this book
Table of Contents (16 chapters)
Qt5 C++ GUI Programming Cookbook
Credits
About the Author
About the Reviewer
www.PacktPub.com
Preface
Index

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 couples of things we need to change. First, open up 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:

  2. After that, open up mainwindow.h and add the following variables under private inheritance:

    private:
      Ui::MainWindow *ui;
      QSqlDatabase db;
      bool connected;
      int currentID;
    
  3. Next, open up mainwindow.cpp and go to the class constructor. It is still pretty much the same as the previous example, except we store the database connection status in a Boolean variable called connected and we also obtain the ID...