Introducing Qt 6Learn to Build Fun Apps & Gamesfor Mobile & Desktop in C++Ben CoeppIntroducing Qt 6: Learn to Build Fun Apps & Games for Mobile & Desktop in C++ Ben Coepp Kln, Germany ISBN-13 (pbk): 978-1-4842-7489-7 ISBN-13 (electronic): 978-1-4842-7490-3 https://doi.org/10.1007/978-1-4842-7490-3 Copyright 2022 by Ben Coepp This work is subject to copyright. All rights are reserved by the Publisher, whether the whole or part of the material is concerned, specifically the rights of translation, reprinting, reuse of illustrations, recitation, broadcasting, reproduction on microfilms or in any other physical way, and transmission or information storage and retrieval, electronic adaptation, computer software, or by similar or dissimilar methodology now known or hereafter developed. Trademarked names, logos, and images may appear in this book. Rather than use a trademark symbol with every occurrence of a trademarked name, logo, or image we use the names, logos, and images only in an editorial fashion and to the benefit of the trademark owner, with no intention of infringement of the trademark. The use in this publication of trade names, trademarks, service marks, and similar terms, even if they are not identified as such, is not to be taken as an expression of opinion as to whether or not they are subject to proprietary rights. While the advice and information in this book are believed to be true and accurate at the date of publication, neither the authors nor the editors nor the publisher can accept any legal responsibility for any errors or omissions that may be made.
The publisher makes no warranty, express or implied, with respect to the material contained herein. Managing Director, Apress Media LLC: Welmoed Spahr Acquisitions Editor: Steve Anglin Development Editor: Matthew Moodie Coordinating Editor: Mark Powers Copyeditor: Anne Sanow Cover designed by eStudioCalamar Cover image by Andrew Kliatskyi on Unsplash (www.unsplash.com) Distributed to the book trade worldwide by Apress Media, LLC, 1 New York Plaza, New York, NY 10004, U.S.A. Phone 1-800-SPRINGER, fax (201) 348-4505, e-mail orders-ny@springer-sbm.com, or visit www. springeronline.com. Apress Media, LLC is a California LLC and the sole member (owner) is Springer Science + Business Media Finance Inc (SSBM Finance Inc). SSBM Finance Inc is a Delaware corporation.
For information on translations, please e-mail booktranslations@springernature.com; for reprint, paperback, or audio rights, please e-mail bookpermissions@springernature.com. Apress titles may be purchased in bulk for academic, corporate, or promotional use. eBook versions and licenses are also available for most titles. For more information, reference our Print and eBook Bulk Sales web page at http://www.apress.com/bulk-sales. Any source code or other supplementary material referenced by the author in this book is available to readers on GitHub (github.com). For more detailed information, please visit http://www.apress.com/ source- code.
Printed on acid-free paper Table of Contents About the Author v About the Technical Reviewer vii Acknowledgments ix Chapter 1: Introduction 1 1.1 What Is This Book About? ........................................................................................................ 1 1.2 What Will We Be Doing in This Book? ...................................................................................... 2 1.3 Why Qt? ................................................................................................................................... 3 1.4 What Are We Using? ................................................................................................................ 4 1.5 Signals, Warnings, and the Context ......................................................................................... 7 2.1.1 Downloading + Installing Qt .......................................................................................... 7 2.1.2 Downloading and Installing Android Studio ................................................................. 21 2.1.3 Configuring the Android SDK, NDK, and Development Tools ......................................... 28 2.2 First Steps with Qt ................................................................................................................ 37 2.3 Explaining the Basics ............................................................................................................ 52 2.3.1 Project Structure .......................................................................................................... 52 2.3.2 App Structure ................................................................................................................ 55 2.3.3 How Qt Creates an Application ..................................................................................... 56 2.3.4 Structuring Tips and Tricks ........................................................................................... 57 2.4 First Real Projects ................................................................................................................. 58 2.4.1 Taskmaster ................................................................................................................... 58 2.4.2 Hang-Man ................................................................................................................... 121 2.4.3 Rock-Paper-Scissors Game ........................................................................................ 182 iii Table of ConTenTs Chapter 3: Components, Features, and Things to Remember 267 3.1 Components ........................................................................................................................ 267 3.1.1 List View ..................................................................................................................... 268 3.1.2 Stack View .................................................................................................................. 271 3.1.3 Swipe View ................................................................................................................. 272 3.1.4 Buttons ....................................................................................................................... 273 3.1.5 Mouse Area ................................................................................................................. 276 3.1.6 Text Field .................................................................................................................... 277 3.1.7 Rectangle ................................................................................................................... 279 3.1.8 Delegates .................................................................................................................... 280 3.1.9 Models ........................................................................................................................ 281 3.1.10 Custom Components ................................................................................................ 282 3.1.11 Qt Charts ................................................................................................................... 284 3.1.12 JSON for Beginners (and How You Might Use It in Qt) .............................................. 293 3.2 Features .............................................................................................................................. 295 3.2.1 C++ Integration .......................................................................................................... 295 3.2.2 Translation Files .......................................................................................................... 301 3.2.3 Git in Qt ....................................................................................................................... 302 3.2.4 Qt Animation ............................................................................................................... 303 3.2.5 Databases in Qt .......................................................................................................... 306 3.3 Things to Remember ........................................................................................................... 309 3.3.1 Writing Diagrams for Qt .............................................................................................. 310 3.4 Advanced Topics in Qt ......................................................................................................... 311 3.4.1 Mobile Applications .................................................................................................... 311 3.4.2 Interactive and Real-Time Data .................................................................................. 312 Appendix A: Sources 315 Final Thoughts 317 Contact Information .................................................................................................................. 318 Index 319 iv
Next page