Hands-On GUI Programming with C++ and Qt5
eBook - ePub

Hands-On GUI Programming with C++ and Qt5

  1. 404 pages
  2. English
  3. ePUB (mobile friendly)
  4. Available on iOS & Android
eBook - ePub

Hands-On GUI Programming with C++ and Qt5

About this book

Create visually appealing and feature-rich applications by using Qt 5 and the C++ language

Key Features

  • Explore Qt 5's powerful features to easily design your GUI application
  • Leverage Qt 5 to build attractive cross-platform applications
  • Work with Qt modules for multimedia, networking, and location, to customize your Qt applications

Book Description

Qt 5, the latest version of Qt, enables you to develop applications with complex user interfaces for multiple targets. It provides you with faster and smarter ways to create modern UIs and applications for multiple platforms. This book will teach you to design and build graphical user interfaces that are functional, appealing, and user-friendly.

In the initial part of the book, you will learn what Qt 5 is and what you can do with it. You will explore the Qt Designer, discover the different types of widgets generally used in Qt 5, and then connect your application to the database to perform dynamic operations. Next, you will be introduced to Qt 5 chart which allows you to easily render different types of graphs and charts and incorporate List View Widgets in your application. You will also work with various Qt modules, like QtLocation, QtWebEngine, and the networking module through the course of the book. Finally, we will focus on cross-platform development with QT 5 that enables you to code once and run it everywhere, including mobile platforms.

By the end of this book, you will have successfully learned about high-end GUI applications and will be capable of building many more powerful, cross-platform applications.

What you will learn

  • Implement tools provided by Qt 5 to design a beautiful GUI
  • Understand different types of graphs and charts supported by Qt 5
  • Create a web browser using the Qt 5 WebEngine module and web view widget
  • Connect to the MySQL database and display data obtained from it onto the Qt 5 GUI
  • Incorporate the Qt 5 multimedia and networking module in your application
  • Develop Google Map-like applications using Qt 5's location module
  • Discover cross-platform development by exporting the Qt 5 application to different platforms
  • Uncover the secrets behind debugging Qt 5 and C++ applications

Who this book is for

This book will appeal to developers and programmers who would like to build GUI-based applications. Basic knowledge of C++ is necessary and the basics of Qt would be helpful.

Frequently asked questions

Yes, you can cancel anytime from the Subscription tab in your account settings on the Perlego website. Your subscription will stay active until the end of your current billing period. Learn how to cancel your subscription.
No, books cannot be downloaded as external files, such as PDFs, for use outside of Perlego. However, you can download books within the Perlego app for offline reading on mobile or tablet. Learn more here.
Perlego offers two plans: Essential and Complete
  • Essential is ideal for learners and professionals who enjoy exploring a wide range of subjects. Access the Essential Library with 800,000+ trusted titles and best-sellers across business, personal growth, and the humanities. Includes unlimited reading time and Standard Read Aloud voice.
  • Complete: Perfect for advanced learners and researchers needing full, unrestricted access. Unlock 1.4M+ books across hundreds of subjects, including academic and specialized titles. The Complete Plan also includes advanced features like Premium Read Aloud and Research Assistant.
Both plans are available with monthly, semester, or annual billing cycles.
We are an online textbook subscription service, where you can get access to an entire online library for less than the price of a single book per month. With over 1 million books across 1000+ topics, we’ve got you covered! Learn more here.
Look out for the read-aloud symbol on your next book to see if you can listen to it. The read-aloud tool reads text aloud for you, highlighting the text as it is being read. You can pause it, speed it up and slow it down. Learn more here.
Yes! You can use the Perlego app on both iOS or Android devices to read anytime, anywhere — even offline. Perfect for commutes or when you’re on the go.
Please note we cannot support devices running on iOS 13 and Android 7 or earlier. Learn more about using the app.
Yes, you can access Hands-On GUI Programming with C++ and Qt5 by Lee Zhi Eng in PDF and/or ePUB format, as well as other popular books in Computer Science & Application Development. We have over one million books available in our catalogue for you to explore.

Information

Database Connection

In the previous chapter, we learned how to create a login page from scratch. However, it is not functional yet, as the login page is not connected to a database. In this chapter, you will learn how to connect your Qt application to a MySQL (or MariaDB) database that validates login credentials.
In this chapter, we will cover the following topics:
  • Introducing the MySQL database system
  • Setting up the MySQL database
  • SQL commands
  • Database connection in Qt
  • Functional login page
We will walk through this chapter in a step-by-step approach to discover the powerful features that come with Qt and allow your application to connect directly to a database without any additional third-party dependencies. Database querying is a huge topic by itself, but we will be able to learn the most basic commands from scratch through examples and practical methods.
Qt supports multiple different types of database systems:
  • MySQL (or MariaDB)
  • SQLite (version 2 and 3)
  • IBM DB2
  • Oracle
  • ODBC
  • PostgreSQL
  • Sybase Adaptive Server
Two of the most popular ones are MySQL and SQLite. The SQLite database is usually used offline and it doesn't require any setup as it uses an on-disk file format for storing data. Therefore, in this chapter, we will learn how to set up a MySQL database system instead, and at the same time learn how to connect our Qt application to a MySQL database. The C++ code used to connect to the MySQL database can be reused for connecting to other database systems without many alterations.

Introducing the MySQL database system

MySQL is an open source database management system based on the relational model, which is the most common method used by modern database systems to store information for various purposes.
Unlike some other legacy models—such as an object database system or a hierarchical database system—the relational model has been proven to be more user friendly and performs well beyond the other models. That's the reason why most of the modern database systems we see today are mostly using this method.
MySQL was originally developed by a Swedish company called MySQL AB, and its name is the combination of My, the name of the daughter of the company's co-founder, and SQL, the abbreviation for Structured Query Language.
Similar to Qt, MySQL has also been owned by multiple different people throughout its history. The most notable acquisition happened in 2008, where Sun Microsystems bought MySQL AB for $1 billion. One year later in 2009, Oracle Corporation acquired Sun Microsystems, and so MySQL is owned by Oracle up to this day. Even though MySQL changed hands several times, it still remains as an open source software that allows users to change the code to suit their own purposes.
Due to its open source nature, there are also other database systems out there that were derived/forked from the MySQL project, such as MariaDB, Percona Server, and so on. However, these alternatives are not fully compatible with MySQL as they have modified it to suit their own needs, and therefore some of the commands may be varied among these systems.
According to a 2017 survey carried out by Stack Overflow, MySQL is the most widely used database system among web developers, as we can see in the following screenshot:
The survey result indicates that what you learn in this chapter can be applied to not just Qt projects but also web, mobile app, and other types of applications.
Furthermore, MySQL and its variants are being used by big corporations and project groups such as Facebook, YouTube, Twitter, NASA, Wordpress, Drupal, Airbnb, Spotify, and so on and so forth. This means that you can easily get answers when encountering any technical issues during development.
For more information regarding MySQL, please visit:
https://www.mysql.com

Setting up the MySQL database

There are many different ways to set up your MySQL database. It really depends on the type of platforms you are running, whether it is Windows, Linux, Mac, or any other type of operating system; it will also depend on the purpose of your database—whether it's for development and testing, or for a large-scale production server.
For large scale services (such as social media), the best way is to compile MySQL from the source, because such as project requires a ton of optimization, configuration, and sometimes customization in order to handle the large amount of users and traffic.
However, you can just download the pre-compiled binaries if you're going for normal use, as the default configuration is pretty sufficient for that. You can install a standalone MySQL installer from their official website or the download installation packages that come with several other pieces of software besides MySQL.
In this chapter, we will be using a software package called XAMPP, which is a web server stack package developed by a group called Apache Friends. This package comes with Apache, MariaDB, PHP, and other optional services that you can add on during the installation process. Previously, MySQL was part of the package, but it has since been replaced with MariaDB starting from version 5.5.30 and 5.6.14. MariaDB works almost the same as MySQL, except those commands involving advanced features, which we will not be using in this book.
The reason why we use XAMPP is that it has a control panel that can easily start and stop the services without using Command Prompt, and provides easy access to the configuration files without you having to dig into the installation directory by yourself. It is very quick and efficient for application development that involves frequent testings. However, it is not recommended that you use XAMPP on a production server as some of the security features have been disabled by default.
Alternatively, you may also install MySQL through other similar software packages such as AppServ, AMPPS, LAMP (Linux only), WAMP (Windows only), ZendServer, and so on.
Now, let's learn how to install XAMPP:
  1. First, go to their website at https://www.apachefriends.org and click on one of the download buttons located at the bottom of your screen, w...

Table of contents

  1. Title Page
  2. Copyright and Credits
  3. Packt Upsell
  4. Contributors
  5. Preface
  6. Introduction to Qt
  7. Qt Widgets and Style Sheets
  8. Database Connection
  9. Graphs and Charts
  10. Item Views and Dialogs
  11. Integrating Web Content
  12. Map Viewer
  13. Graphics View
  14. The Camera Module
  15. Instant Messaging
  16. Implementing a Graphics Editor
  17. Cloud Storage
  18. Multimedia Viewers
  19. Qt Quick and QML
  20. Cross-Platform Development
  21. Testing and Debugging
  22. Other Books You May Enjoy