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

Hands-On GUI Programming with C++ and Qt5

Lee Zhi Eng

Compartir libro
  1. 404 páginas
  2. English
  3. ePUB (apto para móviles)
  4. Disponible en iOS y Android
eBook - ePub

Hands-On GUI Programming with C++ and Qt5

Lee Zhi Eng

Detalles del libro
Vista previa del libro
Índice
Citas

Información del libro

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.

Preguntas frecuentes

¿Cómo cancelo mi suscripción?
Simplemente, dirígete a la sección ajustes de la cuenta y haz clic en «Cancelar suscripción». Así de sencillo. Después de cancelar tu suscripción, esta permanecerá activa el tiempo restante que hayas pagado. Obtén más información aquí.
¿Cómo descargo los libros?
Por el momento, todos nuestros libros ePub adaptables a dispositivos móviles se pueden descargar a través de la aplicación. La mayor parte de nuestros PDF también se puede descargar y ya estamos trabajando para que el resto también sea descargable. Obtén más información aquí.
¿En qué se diferencian los planes de precios?
Ambos planes te permiten acceder por completo a la biblioteca y a todas las funciones de Perlego. Las únicas diferencias son el precio y el período de suscripción: con el plan anual ahorrarás en torno a un 30 % en comparación con 12 meses de un plan mensual.
¿Qué es Perlego?
Somos un servicio de suscripción de libros de texto en línea que te permite acceder a toda una biblioteca en línea por menos de lo que cuesta un libro al mes. Con más de un millón de libros sobre más de 1000 categorías, ¡tenemos todo lo que necesitas! Obtén más información aquí.
¿Perlego ofrece la función de texto a voz?
Busca el símbolo de lectura en voz alta en tu próximo libro para ver si puedes escucharlo. La herramienta de lectura en voz alta lee el texto en voz alta por ti, resaltando el texto a medida que se lee. Puedes pausarla, acelerarla y ralentizarla. Obtén más información aquí.
¿Es Hands-On GUI Programming with C++ and Qt5 un PDF/ePUB en línea?
Sí, puedes acceder a Hands-On GUI Programming with C++ and Qt5 de Lee Zhi Eng en formato PDF o ePUB, así como a otros libros populares de Computer Science y Application Development. Tenemos más de un millón de libros disponibles en nuestro catálogo para que explores.

Información

Año
2018
ISBN
9781788393744
Edición
1

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...

Índice