Table Of ContentA Guide to
Qt 6
For the fun in learning
about Qt
and the World we reside in
BenCoepp
Ben Coepp
2
Before we get
started
Before we can get started with the book there are a few things I
need to make clear, one is for legal reasons and the other is for
the simple fact that I want to be honest with you how this book
works and who was involved with the creation of the book.
First of I am not in any way, shape and or form linked or a part
of Qt, the Qt Company. Therefore, I do not represent Qt or the
Qt Company with this book, the statements I bring forth and the
content I provide.
I am responsible for all the content and work in this book. If
there are problems, mistakes, or misconceptions, then they are
my responsibilities. If you want to contact me all my contact
information can be found in Chapter 8 of this book.
Content
Before we get started ............................................................... 3
1.1 About Me ...................................................................... 7
1.2 What is this Book about? ............................................ 8
1.3 What are we doing in this Book? ............................... 9
1.4 What are we using? ................................................... 11
1.5 Signals, Warnings, and ............................................. 12
the Context ....................................................................... 12
2 Content ................................................................................. 14
2.1 Setting up the Tools we need ................................... 14
2.1.1 Downloading + Installing Qt ............................ 15
2.1.3 Downloading + Installing Android Studio ...... 27
2.1.4 Configuring the Android SDK, NDK and
Development Tools ................................................... 35
2.2 First Baby Steps with Qt ........................................... 44
2.3 Explaining the Basics ................................................ 60
2.3.1 Project Structure .............................................. 60
2.3.2 App Structure ................................................... 62
2.3.3 How does Qt make an app out of this? .......... 63
2.3.4 Structuring Tips and Tricks ............................. 65
2.4 First real Projects ...................................................... 66
2.4.1 Taskmaster ....................................................... 67
- Project Creation - ................................................. 67
- Loading the Pages - ............................................. 72
- How does the app supposed to work - .............. 94
4
- List View and displaying Data - .......................... 96
- Adding Data to the List - ................................... 102
- Deleting Data - .................................................... 121
- Cleaning up the Application - ........................... 123
- Deploying the Application - .............................. 125
- What did we learn - ............................................ 127
2.4.2 Hang-Man ........................................................ 135
- Create Project - .................................................. 136
- Load and Main Page - ........................................ 139
- Functionality - .................................................... 142
- Building the App - .............................................. 144
- Deploying the App - ........................................... 183
- What did we learn - ........................................... 196
2.4.3 Rock-Paper-Scissors Game .......................... 198
- Project Creation - ............................................... 198
- Functionality - .................................................... 204
- Creating the basic Game -................................. 206
- Adding the Project to Git - ................................ 211
- Creating the Home_Page - ................................ 221
- Creating the Game_Page - ................................ 226
- Creating the End_Page - ................................... 246
- Fixing the mess - ............................................... 254
- Adding Local Storage - ..................................... 266
- Deploy Application to Android - ....................... 274
- What did we learn - ............................................ 283
3 Components, Features and Things to remember ........... 286
3.1 Components ............................................................. 287
3.1.1 ListView .............................................................. 287
3.1.2 Stack View .......................................................... 292
3.1.3 Swipe View ......................................................... 293
3.1.4 Buttons ............................................................... 295
3.1.5 Mouse Area ........................................................ 298
3.1.6 Text Field ............................................................ 299
3.1.7 Rectangle ........................................................... 303
3.1.8 Delegates ........................................................... 305
3.1.9 Models ................................................................ 306
3.1.10 Custom Components ...................................... 308
3.1.11 Qt Charts .......................................................... 310
3.1.12 JSON in Qt........................................................ 320
3.2 Features .................................................................... 322
3.2.1 C++ Integration .................................................. 322
3.2.2 Translation Files ................................................ 329
3.2.3 Git in Qt .............................................................. 330
3.2.4 Qt Animation ...................................................... 332
3.2.5 Databases in Qt ................................................. 336
3.3 Things to remember ................................................ 339
3.3.1 Writing Diagrams for Qt .................................... 341
3.4 Advanced Topics in Qt ............................................ 343
3.4.1 Mobile Applications ....................................... 343
3.4.2 Interactive and Real Time Data ..................... 345
4 Final Thoughts ................................................................... 348
5 Thank you .......................................................................... 351
6 Sources .............................................................................. 353
7 Index ................................................................................... 354
8 Contact Me ......................................................................... 355
6
1 Introduction
Before we start with the book, there are a few things I like to talk
about, these are not essential for buying this book, and I would
even go so far as to tell you to skip this part if you are only here
for the content and the tutorials. But if you want to know a little
bit more about me, what we are going to do and how we are
going to do it, then read along, for all others, refer to the Index
and jump straight into Chapter 2 Content.
1.1 About Me
First off congratulations for buying this book, now that you
already bought the book you might have some questions about
what we are going to talk about and who the author, me is. The
answers to what we are doing will be provided later on, but the
question of who I am I can answer now.
My name is Ben Cöppicus, currently I am 20 years old living in
Germany and working as a software engineer. I am still young
so I already know this might turn some people off the topic and
off reading the book immediately, and I am terribly sorry for this.
I am just young, and there is nothing I can really do about that.
But Qt is dear to my heart and I use it nearly every day for my
own work, my own development projects, unfortunately not for
the company I work for they currently do not use Qt.
My focus and stuff I generally do is in mobile and desktop
development until now my focus was on creating applications
for office specific purpose like financing and general
management as well as task management.
Because I am still young, there will be some people that
question my knowledge and what I even know about specific
topics, that I talk about and I can fully understand this. And I will
be completely honest with you I do not know or understand
everything. I have specific knowledge in some extremely
specific parts about Qt. I talk about these parts I want to share
with you and want to make more people aware of and more
people understand how stuff like this works but this knowledge
is extremely limited. I am not a university professor, I am not a
teacher and for lack of a better word, I will never pretend to be
one. So, prepare yourself for reading a lot of this is my opinion,
and this is stuff I do, so always take the stuff you read in this
book with a grain of salt. I will try to be as accurate and
descriptive and generally as best of an author and a teacher as I
can be, but Qt is an exceptionally large and complicated topic
with a lot of people that have a far greater understanding and
more rounded out knowledge of what Qt is and how it functions.
1.2 What is this Book about?
I really like Qt and the development experience using it. But it
lacks tutorials, videos, and books about it, at least if you look at
the last two years, there was not so much new content provided.
Learning it can be done throw just trying out all the features and
experimentation but that is not a good way to learn Qt in my
opinion.
8
You could also go through the examples provided by Qt, but
these are also not the greatest1. But that only motivated me
more for writing this book. This books purpose can be boiled
down to the fact that by the end of this book you should be able
to make your own applications with Qt. May they be mobile or
desktop applications. I am not all knowing, or the only voice on
matters in Qt. But I know how to use it and how to best get
started using Qt, and that is in my opinion the most important
part. I am not trying to push a specific way of using Qt or
programming onto you, just showing mine. I have my own way
of doing it and sometimes this is not the best way or the way
that you would most likely find elsewhere.
My way of doing it can be boiled down to, I want to achieve the
things I want, and I am willing to do that with every way
available to me. This just means that I do not always use the
right way but always the way that best achieves the results I
want.
1.3 What are we doing in this
Book?
This book will take you on a ride throw a lot of features Qt has to
offer. We will be starting with writing our first few applications
and the concepts behind them. From there we will be going over
more complicated concepts and principles behind making good
applications. We will also cover most of the components that are
relevant to making applications, at least those which you will
1 This does not mean it is bad, but there are some parts which are out of date, but
they are still extremely great showcases and can really help you learn and
understand specific topics in Qt
use on a regular basis. And finally, we are going to create some
real applications that you would use in real life.
What do I mean by that? Well, what you would find in a lot of
books out there are applications that might be considered good
educational content, but not actual good applications. This, I
want to alleviate with bringing in my own work-related projects
that I needed to do. These in my opinion will best represent the
type of work you will need to do. They are still fun applications
that I constructed in such a way as to make them as enjoyable
as possible. Overall, this book is supposed to teach you Qt, and
all the underlying concepts, principles, and elements. As well as
general programming and development know-how. This will also
be a large focus later in the book. The middle part that goes
over the components that Qt provide can also be used as
documentation and a place to look for specific solution or an
example. But remember, I do not want to replace the Qt Docs,
they might be outdated at some places but overall, they are
compared to a lot of other software documentation extremely
good. But what do I even mean with outdated? Well, if you are
someone new learning Qt it might come to you as that some
part of the documentation is better presented and polished then
others. This comes down to how important the subject or
component is and how frequently it is updated and used. And
with outdated I specifically mean documentations like the Qml
Local Storage, or QML Calendar that are still used and new
users might want to implement, but they are not really that well
supported anymore or are somewhat hard to understand or get
into. And Chapter 3 of this book will be all about that, shining a
light on some of the components that you will tend to use quit a
lot throw your development years, but that might not be
explained enough on the Qt Docs for a complete beginner.
And if you are someone who is a little bit more experienced you
might find some useful information none the less.
10