Cross-Platform Development with Qt 6 and Modern C++

Book description

Enhance your cross-platform programming abilities with the powerful features and capabilities of Qt 6

Key Features

  • Leverage Qt and C++ capabilities to create modern, cross-platform applications that can run on a wide variety of software applications
  • Explore what’s new in Qt 6 and understand core concepts in depth
  • Build professional customized GUI applications with the help of Qt Creator

Book Description

Qt is a cross-platform application development framework widely used for developing applications that can run on a wide range of hardware platforms with little to no change in the underlying codebase. If you have basic knowledge of C++ and want to build desktop or mobile applications with a modern graphical user interface (GUI), Qt is the right choice for you. Cross-Platform Development with Qt 6 and Modern C++ helps you understand why Qt is one of the favorite GUI frameworks adopted by industries worldwide, covering the essentials of programming GUI apps across a multitude of platforms using the standard C++17 and Qt 6 features.

Starting with the fundamentals of the Qt framework, including the features offered by Qt Creator, this practical guide will show you how to create classic user interfaces using Qt Widgets and touch-friendly user interfaces using Qt Quick. As you advance, you'll explore the Qt Creator IDE for developing applications for multiple desktops as well as for embedded and mobile platforms. You will also learn advanced concepts about signals and slots. Finally, the book takes you through debugging and testing your app with Qt Creator IDE.

By the end of this book, you'll be able to build cross-platform applications with a modern GUI along with the speed and power of native apps.

What you will learn

  • Write cross-platform code using the Qt framework to create interactive applications
  • Build a desktop application using Qt Widgets
  • Create a touch-friendly user interface with Qt Quick
  • Develop a mobile application using Qt and deploy it on different platforms
  • Get to grips with Model/View programming with Qt Widgets and Qt Quick
  • Discover Qt’s graphics framework and add animations to your user interface
  • Write test cases using the Qt Test framework and debug code
  • Build a translation-aware application
  • Follow best practices in Qt to write high-performance code

Who this book is for

This book is for application developers who want to use C++ and Qt to create modern, responsive applications that can be deployed to multiple operating systems such as Microsoft Windows, Apple macOS, and Linux desktop platforms. Although no prior knowledge of Qt is expected, beginner-level knowledge of the C++ programming language and object-oriented programming system (OOPs) concepts will be helpful.

Table of contents

  1. Cross-Platform Development with Qt 6 and Modern C++
  2. Contributors
  3. About the author
  4. About the reviewers
  5. Preface
    1. Who this book is for
    2. What this book covers
    3. To get the most out of this book
    4. Download the example code files
    5. Download the color images
    6. Conventions used
    7. Get in touch
    8. Reviews
  6. Section 1: The Basics
  7. Chapter 1: Introduction to Qt 6
    1. Technical requirements
    2. Introducing Qt
    3. Reasons for using Qt
    4. Downloading and installing Qt
      1. Downloading Qt
      2. Installing Qt on Windows
      3. Installing Qt on Linux
      4. Installing Qt on macOS
      5. Updating or removing Qt
    5. Building Qt 6 from source
      1. Installing Qt on Windows from source
      2. Installing Qt on Linux from source
      3. Installing Qt on macOS from source
    6. Summary
  8. Chapter 2: Introduction to Qt Creator
    1. Technical requirements
    2. Exploring the Qt Creator UI
    3. Building a simple Qt application
    4. Understanding advanced options
      1. Managing kits
      2. Qt Versions
      3. Environment
      4. Keyboard shortcuts
      5. Text Editor
      6. Splitting the coding window
      7. Build options
      8. Qt Assistant
    5. Summary
  9. Chapter 3: GUI Design Using Qt Widgets
    1. Technical requirements
    2. Introducing Qt widgets
    3. Creating a UI with Qt Designer
    4. Managing layouts
      1. QVBoxLayout
      2. QHBoxLayout
      3. QGridLayout
    5. Creating custom widgets
    6. Creating Qt Style Sheets and custom themes
      1. Using a QSS file
    7. Exploring custom styles
      1. Creating a custom style
      2. Using a custom style
    8. Using widgets, windows, and dialogs
    9. Summary
  10. Chapter 4: t Quick and QML
    1. Technical requirements
    2. Getting started with QML and Qt Quick
      1. Understanding the QML type system
    3. Understanding Qt Quick Controls
      1. Styling Qt Quick Controls
    4. Creating a simple Qt Quick application
    5. Designing a UI with Qt Quick Designer
    6. Positioners and layouts in QML
      1. Manual positioning
      2. Positioning with anchors
      3. Positioners
      4. Repeater
      5. Qt Quick Layouts
    7. Integrating QML with C++
      1. Embedding C++ objects into QML with context properties
      2. Registering a C++ class with the QML engine
      3. Creating a QML extension plugin
      4. Invoking QML methods inside a C++ class
      5. Exposing a QML object pointer to C++
    8. Integrating QML with JS
      1. Importing a directory in QML
    9. Handling mouse and touch events
      1. MouseArea
      2. MultiPointTouchArea
      3. TapHandler
      4. SwipeView
    10. Summary
  11. Section 2: Cross-Platform Development
  12. Chapter 5: Cross-Platform Development
    1. Technical requirements
    2. Understanding cross-platform development
    3. Understanding compilers
      1. Adding custom compilers
    4. Building with qmake
    5. Qt Project (.pro) files
      1. Understanding differences between .pro and .pri files
    6. Understanding build settings
    7. Platform-specific settings
    8. Using Qt with Microsoft Visual Studio
    9. Running a Qt application on Linux
    10. Running a Qt application on macOS and iOS
      1. Configuring Qt Creator for iOS
      2. Configuring Qt Creator for Android
    11. Other Qt-supported platforms
    12. Porting from Qt 5 into Qt 6
    13. Summary
  13. Section 3: Advanced Programming, Debugging, and Deployment
  14. Chapter 6: Signals and Slots
    1. Technical requirements
    2. Understanding Qt signals and slots
      1. Understanding syntax
      2. Declaring signals and slots
      3. Connecting the signal to the slot
      4. Connecting a single signal to multiple slots
      5. Connecting multiple signals to a single slot
      6. Connecting a signal to another signal
    3. The working mechanism of Qt signals and slots
      1. Qt's meta-object system
      2. MOC generated code
    4. Getting to know Qt's property system
      1. Reading and writing properties with the Meta-Object System
    5. Using signals and slots in Qt Designer
    6. Understanding signals and the handler event system in QML
      1. Adding a signal in QML
      2. Connecting a signal to a function
      3. Connecting a signal to a signal
      4. Defining property attributes and understanding property binding
      5. Integrating signals and slots between C++ and QML
    7. Understanding events and the event loop
    8. Managing events with an event filter
    9. Drag and drop
      1. Drag and drop in Qt Widgets
      2. Drag and drop in QML
    10. Summary
  15. Chapter 7: Model View Programming
    1. Technical requirements
    2. Understanding the M/V architecture
      1. Model
      2. Delegate
      3. Views in Qt Widgets
    3. Creating a simple Qt Widgets application using the M/V pattern
    4. Understanding Models and Views in QML
      1. Views in Qt Quick
      2. Models in Qt Quick
    5. Using C++ Models with QML
    6. Creating a simple M/V application with Qt Quick
    7. Summary
  16. Chapter 8: Graphics and Animations
    1. Technical requirements
    2. Understanding Qt's graphics framework
    3. QPainter and 2D graphics
      1. Understanding the paint system
      2. Using the coordinate system
      3. Drawing and filling
      4. Drawing with QPainter
    4. Introducing the Graphics View framework
    5. Understanding the Qt OpenGL module
      1. Qt OpenGL and Qt Widgets
    6. Graphics in Qt Quick
      1. Qt OpenGL and Qt Quick
      2. Custom Qt Quick items using QPainter
    7. Understanding the Qt Quick scene graph
      1. Qt Quick scene graph structure
      2. Rendering using a scene graph
      3. Using a scene graph with the Native Graphics
      4. 3D graphics with Qt Quick 3D
    8. Shader effects
    9. Using the Canvas QML type
    10. Understanding particle simulations
    11. Animation in Qt Widgets
    12. Animation and transitions in Qt Quick
      1. Controlling animations
    13. States, state machine, and transitions in Qt Quick
    14. The state machine in Qt Widgets
    15. Summary
  17. Chapter 9: Testing and Debugging
    1. Technical requirements
    2. Debugging in Qt
      1. Debuggers supported by Qt
    3. Debugging strategies
    4. Debugging a C++ application
    5. Debugging a Qt Quick application
    6. Testing in Qt
      1. Unit testing in Qt
    7. Integrating with Google's C++ testing framework
    8. Testing Qt Quick applications
    9. GUI testing tools
      1. The Linux Desktop Testing Project (LDTP)
      2. GammaRay
      3. Squish
    10. Summary
  18. Chapter 10: Deploying Qt Applications
    1. Technical requirements
    2. Understanding the need for deployment
      1. Choosing between static and dynamic libraries
    3. Deploying on desktop platforms
      1. Deploying on Windows
      2. Windows deployment tool
      3. Deploying on Linux
      4. Deploying on macOS
    4. Using the Qt Installer Framework
    5. Deploying on Android
    6. Other installation tools
    7. Summary
  19. Chapter 11: Internationalization
    1. Technical requirements
    2. Understanding internationalization and Qt Linguist
    3. Writing source code for translation
    4. Loading translations in a Qt application
    5. Switching languages dynamically
    6. Internationalization with Qt Widgets
      1. Adding dynamic translation to a Qt Widgets application
    7. Internationalization with Qt Quick
      1. Translating dynamically in a Qt Quick application
    8. Deploying translations
    9. Summary
  20. Chapter 12: Performance Considerations
    1. Technical requirements
    2. Understanding performance optimization
    3. Optimizing C++ code
    4. Using concurrency, parallelism, and multithreading
    5. Profiling a Qt Quick application using QML Profiler and Flame Graph
    6. Other Qt Creator analysis tools
    7. Optimizing graphical performance
    8. Creating benchmarks
    9. Different analysis tools and optimization strategies
      1. Memory profiling and analysis tools
      2. Optimizing during linking
      3. Building a Qt application faster
    10. Performance considerations for Qt Widgets
    11. Learning best practices of QML coding
    12. Summary
    13. Why subscribe?
  21. Other Books You May Enjoy
    1. Packt is searching for authors like you
    2. Leave a review - let other readers know what you think

Product information

  • Title: Cross-Platform Development with Qt 6 and Modern C++
  • Author(s): Nibedit Dey
  • Release date: June 2021
  • Publisher(s): Packt Publishing
  • ISBN: 9781800204584