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

Hands-On GUI Programming with C++ and Qt5

Lee Zhi Eng

Buch teilen
  1. 404 Seiten
  2. English
  3. ePUB (handyfreundlich)
  4. Über iOS und Android verfügbar
eBook - ePub

Hands-On GUI Programming with C++ and Qt5

Lee Zhi Eng

Angaben zum Buch
Buchvorschau
Inhaltsverzeichnis
Quellenangaben

Über dieses Buch

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.

Häufig gestellte Fragen

Wie kann ich mein Abo kündigen?
Gehe einfach zum Kontobereich in den Einstellungen und klicke auf „Abo kündigen“ – ganz einfach. Nachdem du gekündigt hast, bleibt deine Mitgliedschaft für den verbleibenden Abozeitraum, den du bereits bezahlt hast, aktiv. Mehr Informationen hier.
(Wie) Kann ich Bücher herunterladen?
Derzeit stehen all unsere auf Mobilgeräte reagierenden ePub-Bücher zum Download über die App zur Verfügung. Die meisten unserer PDFs stehen ebenfalls zum Download bereit; wir arbeiten daran, auch die übrigen PDFs zum Download anzubieten, bei denen dies aktuell noch nicht möglich ist. Weitere Informationen hier.
Welcher Unterschied besteht bei den Preisen zwischen den Aboplänen?
Mit beiden Aboplänen erhältst du vollen Zugang zur Bibliothek und allen Funktionen von Perlego. Die einzigen Unterschiede bestehen im Preis und dem Abozeitraum: Mit dem Jahresabo sparst du auf 12 Monate gerechnet im Vergleich zum Monatsabo rund 30 %.
Was ist Perlego?
Wir sind ein Online-Abodienst für Lehrbücher, bei dem du für weniger als den Preis eines einzelnen Buches pro Monat Zugang zu einer ganzen Online-Bibliothek erhältst. Mit über 1 Million Büchern zu über 1.000 verschiedenen Themen haben wir bestimmt alles, was du brauchst! Weitere Informationen hier.
Unterstützt Perlego Text-zu-Sprache?
Achte auf das Symbol zum Vorlesen in deinem nächsten Buch, um zu sehen, ob du es dir auch anhören kannst. Bei diesem Tool wird dir Text laut vorgelesen, wobei der Text beim Vorlesen auch grafisch hervorgehoben wird. Du kannst das Vorlesen jederzeit anhalten, beschleunigen und verlangsamen. Weitere Informationen hier.
Ist Hands-On GUI Programming with C++ and Qt5 als Online-PDF/ePub verfügbar?
Ja, du hast Zugang zu Hands-On GUI Programming with C++ and Qt5 von Lee Zhi Eng im PDF- und/oder ePub-Format sowie zu anderen beliebten Büchern aus Computer Science & Application Development. Aus unserem Katalog stehen dir über 1 Million Bücher zur Verfügung.

Information

Jahr
2018
ISBN
9781788393744

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

Inhaltsverzeichnis