Book Image

Getting Started with Qt 5

By : Benjamin Baka
Book Image

Getting Started with Qt 5

By: Benjamin Baka

Overview of this book

Qt is a cross-platform application framework and widget toolkit that is used to create GUI applications that can run on different hardware and operating systems. The main aim of this book is to introduce Qt to the reader. Through the use of simple examples, we will walk you through building blocks without focusing too much on theory. Qt is a popular tool that can be used for building a variety of applications, such as web browsers, media players such as VLC, and Adobe Photoshop. Following Qt installation and setup, the book dives straight into helping you create your first application. You will be introduced to Widgets, Qt's interface building block, and the many varieties that are available for creating GUIs. Next, Qt's core concept of signals and slots are well illustrated with sufficient examples. The book further teaches you how to create custom widgets, signals and slots, and how to communicate useful information via dialog boxes. To cap everything off, you will be taken through writing applications that can connect to databases in order to persist data. By the end of the book, you should be well equipped to start creating your own Qt applications and confident enough to pick up more advanced Qt techniques and materials to hone your skills.
Table of Contents (8 chapters)

To get the most out of this book

The beginning of each chapter will begin with a little theory that should help consolidate your understanding. Thereafter, a series of examples are used to explain the concepts and to help the reader grasp the topic better.

This book also avoids continuing with examples from previous chapters. Each chapter's examples are short and do not require the reader to have knowledge of previous chapters. That way, you can pick any chapter you link and work through it.

Appropriate links to set up the environment on Windows have been provided. Linux and macOS platforms have been catered for directly in this book.

Download the example code files

You can download the example code files for this book from your account at www.packt.com. If you purchased this book elsewhere, you can visit www.packt.com/support and register to have the files emailed directly to you.

You can download the code files by following these steps:

  1. Log in or register at www.packt.com.
  2. Select the SUPPORT tab.
  3. Click on Code Downloads & Errata.
  4. Enter the name of the book in the Search box and follow the onscreen instructions.

Once the file is downloaded, please make sure that you unzip or extract the folder using the latest version of:

  • WinRAR/7-Zip for Windows
  • Zipeg/iZip/UnRarX for Mac
  • 7-Zip/PeaZip for Linux

The code bundle for the book is also hosted on GitHub at https://github.com/PacktPublishing/Getting-Started-with-Qt-5. In case there's an update to the code, it will be updated on the existing GitHub repository.

We also have other code bundles from our rich catalog of books and videos available at https://github.com/PacktPublishing/. Check them out!

Download the color images

Conventions used

There are a number of text conventions used throughout this book.

CodeInText: Indicates code words in text, database table names, folder names, filenames, file extensions, pathnames, dummy URLs, user input, and Twitter handles. Here is an example: "To set the password to the connection parameter, the code fragment, db_conn.setPassword(""), is issued."

A block of code is set as follows:

QSqlDatabase db_conn =
QSqlDatabase::addDatabase("QMYSQL", "contact_db");

db_conn.setHostName("127.0.0.1");
db_conn.setDatabaseName("contact_db");
db_conn.setUserName("root");
db_conn.setPassword("");
db_conn.setPort(3306);

When we wish to draw your attention to a particular part of a code block, the relevant lines or items are set in bold:

[default]
exten => s,1,Dial(Zap/1|30)
exten => s,2,Voicemail(u100)
exten => s,102,Voicemail(b100)
exten => i,1,Voicemail(s0)

Any command-line input or output is written as follows:

% mkdir helloWorld
% ./run_executable

Bold: Indicates a new term, an important word, or words that you see on screen. For example, words in menus or dialog boxes appear in the text like this. Here is an example: "It displays the text Hello world ! in a label."

Warnings or important notes appear like this.
Tips and tricks appear like this.