Support Statistics
¥.00 ·
0times
Text Preview (First 20 pages)
Registered users can read the full content for free
Register as a Gaohf Library member to read the complete e-book online for free and enjoy a better reading experience.
Page
1
Ben Coepp A Guide to Qt 6 For the fun in learning about Qt and the World we reside in BenCoepp
Page
2
2
Page
3
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.
Page
4
4 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
Page
5
- 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
Page
6
6 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
Page
7
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
Page
8
8 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.
Page
9
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
Page
10
10 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.
Page
11
1.4 What are we using? As the title of this book suggests we are going to mainly use Qt. And specifically, Qt 6.02 and above. This also comes with the Qt Creator and Qt Design Studio which we are also going to use for all the application development we are going to do. If you already have some knowledge of how Qt works, and you want to use your own desired IDE then feel free to do so. But remember that all the screenshots as well as descriptions will be based on Qt Creator and Design Studio. We also need Android Studio for the Android SDK, SDK Tools and the NDK. This is essential for our Android development. Without it we cannot really do anything. Other than that, I would also recommend getting something like Visual Studio Code or Atom as a Text Editor. We are not going to use this, because we can do everything, we need in Qt Creator and Design Studio. But down the line it would be helpful for creating specific files or writing code that is not highlighted as good as QML2 for instance JavaScript. Which has little to no highlight at all. But you can choose if you want to use this, in this book we are not going to use it, and I will only mention it when it could be used. But I will not be covering the installation of Visual Studio Code or any other Text Editor or IDE, you can use them if you want to, but they are not covered in this book, which means I cannot help you if something goas wrong. If you wanted to develop applications for IOS devices well then, I am sorry to tell you that this will not be covered in this book. 2 For the projects we are doing it makes no difference which Qt version you use, as long as it is above 5.12
Page
12
12 1.5 Signals, Warnings, and the Context As with all books that teach you something, there will come the time where I want to add a bit more information. And for that purpose, I will give a signal. • This might be done using the footnotes1 • A different text colour or cursive writing • Image / Screenshot o And the description below the screenshots These should be readable and easy to find. But I want to minimise the amount of use I make of them. This is for the reason of how I structure the book. I only want to use them in specific places where there is a true need for them and there is no other way. Also remember to check out the page about the book on my website. There you will find a few more passages as well as links to Git Hub where I have a full repository with all the code and resources we use in the project. You do not need this per say but if you have questions that are not answered in the book or are not as clear as you want them to be. Then you can check these resources. But all these signals and warnings are easy to understand and difficult to miss. And as you can see this book is not visually stunning. This was never the point of what I wanted to create, the content and the information I want to teach is the most important part.
Page
13
You will see that I tend to use screenshots on a very regular basis, all screenshots were created using Qt 6 as it is the current version, but if you are running any current version of Qt then all screenshots still hold true. Sometimes I will also use code snippets if I want to show you a lot of code at ones, because using screenshot in that instance would be quit the undertaking and be really confusing at times.
Page
14
14 2 Content The content I provide in this book can generally be read in any way you want, but I would strongly recommend you read it in order so as not to lose focus and miss something important. But later on, you might want to just jump straight to a specific topic or subject that interests you, this is also possible but refer to the Index of this book to figure out where you need to go. 2.1 Setting up the Tools we need Now we come to the least interesting part of this book, downloading, and installing all the tools, software, and SDKs as well as NDKs3 we need. I highly recommend you follow along and install anything you are missing. Except for Android Studio and Qt as well as Qt Creator you can use whatever tool, IDE, or text editor you will not. Just please remember that if you choose your own tools, you might get problems, warnings that this book cannot help you with. But that does not mean that I will leave you hanging, when you stumble across problems like this you can always write me an 3 SDKs and NDKs are fundamental in any development project, they include all the files and data you need to develop your applications
Page
15
email or leave a question on the Amazon page for this book, I will try to help you with any question or problem you might have. 2.1.1 Downloading + Installing Qt If you already know how to install Qt or you want to figure it out yourself, you do not need to follow the steps down below. First of we need to get Qt from somewhere and the best way is through their website. Just type Qt into google.com and it will take you from there. Google Search of Qt Click the first link that says qt.io. Here you will be presented with the homepage of the Qt Company. Here you can find a lot about the product and the services that the Qt Company provides. But for us the only important part is up top.
Page
16
16 Qt Website Top-Bar The Download. Try. button. Clicking this will bring us to the next part. If you want to buy Qt, then you can also click the green Buy Now. Button, but for our needs and what I want to teach you it is not needed. And Qt has a good Open-Source base which has all the features needed for most developers. And I never needed anything else so, we surely do not need to buy Qt. Also, there are only a few features that can be bought with the commercial license. And you only need it if you want to make money selling and providing an application. Next scroll down to the different download links and click on the green button that says Go open source. This will take you to the next section. Download Card for Open-Source Users
Page
17
Here you also need to scroll down near the bottom of the page and click on Download the Qt Online Installer. This will bring you to the final page we need to visit on their website. On the final page you only need to click on the Download Button. This will download the installer. For now, you can close the browser and start the installer. The installation is going to take a while so remember that. But other than this just follow the screenshots down below.
Page
18
18 Login Form of the Qt Installer Here you need to just put in your Qt account name and password. If you do not already have an account, then you can click the Sign-Up link and create an account. Creating an account is mandatory, so if you do not have one click create or go to the Qt website and create one for yourself. If you already have an account, then you fill out the two input forms and then click next. As always keep your password and email a secret, otherwise someone might try stealing your data. This is also why I blacked out my email. Not because I do not want to receive emails from you, but to many emails is also not great.
Page
19
Qt open source runs under the GNU General Public License v34. Therefore, you cannot use this version of Qt we downloaded, the Installer for If it is for commercial use. Qt License Agreement You need to check that you have read and approved of the license agreements and ether type in your company’s name or leave the checkbox by I am an individual. If you have done both then Next will be enabled and we can continue. A little anecdote to this, Qt is not that large of a company, compared to other companies like Amazon or Microsoft. So, if you want to make money selling an app or providing some other kind of monetary service, please buy a Qt License. It helps the company finance the development, and you will not get in legal problems. 4 The GNU General Public License v3 is a special License that allows you to use Qt and its Components and Features for non-commercial use https://www.qt.io/licensing/
Page
20
20 This page can be ignored. We do not have a commercial license and we do not want one, and we do not need one for what we are doing. So, hit Next and continue. If you ask me why I good this page, well I do not know myself and a lot of people online were not able to figure that one out. Expired License Page, you can ignore this here When you did this the installer will retrieve some metainformation and then download it. Depending on your internet connection this can take a while. Also, I had the problem on some machines that even while having a good connection the download took a long time so be aware of that.
Comments 0
Loading comments...
Reply to Comment
Edit Comment