Qt5 Cadaques Release Master
Total Page:16
File Type:pdf, Size:1020Kb
Qt5 Cadaques Release master JRyannel,JThelin December 07, 2020 at 10:51 CET CONTENTS 1 Meet Qt 5 3 1.1 Preface................................................3 1.2 Qt 5 Introduction...........................................4 1.3 Qt Building Blocks..........................................9 1.4 Qt Project............................................... 11 2 Get Started 13 2.1 Installing Qt 5 SDK......................................... 13 2.2 Hello World............................................. 13 2.3 Application Types.......................................... 15 2.4 Summary............................................... 23 3 Qt Creator IDE 25 3.1 The User Interface.......................................... 25 3.2 Registering your Qt Kit....................................... 26 3.3 Managing Projects.......................................... 26 3.4 Using the Editor........................................... 27 3.5 Locator................................................ 27 3.6 Debugging.............................................. 28 3.7 Shortcuts............................................... 28 4 Quick Starter 31 4.1 QML Syntax............................................. 31 4.2 Basic Elements............................................ 36 4.3 Components............................................. 41 4.4 Simple Transformations....................................... 43 4.5 Positioning Elements......................................... 46 4.6 Layout Items............................................. 51 4.7 Input Elements............................................ 53 4.8 Advanced Techniques........................................ 58 5 Fluid Elements 59 5.1 Animations.............................................. 59 5.2 States and Transitions........................................ 74 5.3 Advanced Techniques........................................ 78 6 Qt Quick Controls 2 81 6.1 Introduction to Controls....................................... 81 6.2 An Image Viewer........................................... 83 6.3 Common Patterns.......................................... 97 6.4 The Imagine Style.......................................... 114 6.5 Summary............................................... 118 7 Model-View-Delegate 121 7.1 Concept................................................ 121 i 7.2 Basic Models............................................. 122 7.3 Dynamic Views............................................ 126 7.4 Delegate............................................... 135 7.5 Advanced Techniques........................................ 145 7.6 Summary............................................... 156 8 Felgo 159 8.1 Why choose Felgo?......................................... 159 8.2 Installing Felgo............................................ 161 8.3 Hello World with Felgo....................................... 162 8.4 A Messaging App.......................................... 163 8.5 Advanced Topics........................................... 173 8.6 Summary............................................... 183 9 Canvas Element 185 9.1 Convenient API........................................... 187 9.2 Gradients............................................... 188 9.3 Shadows............................................... 189 9.4 Images................................................ 189 9.5 Transformation............................................ 191 9.6 Composition Modes......................................... 192 9.7 Pixel Buffers............................................. 193 9.8 Canvas Paint............................................. 194 9.9 Porting from HTML5 Canvas.................................... 196 10 Particle Simulations 203 10.1 Concept................................................ 203 10.2 Simple Simulation.......................................... 204 10.3 Particle Parameters.......................................... 206 10.4 Directed Particles........................................... 207 10.5 Particle Painters........................................... 210 10.6 Affecting Particles.......................................... 212 10.7 Particle Groups............................................ 217 10.8 Summary............................................... 224 11 Shader Effects 225 11.1 OpenGL Shaders........................................... 225 11.2 Shader Elements........................................... 226 11.3 Fragment Shaders.......................................... 228 11.4 Wave Effect.............................................. 232 11.5 Vertex Shader............................................. 233 11.6 Curtain Effect............................................ 243 11.7 Qt GraphicsEffect Library...................................... 246 12 Multimedia 249 12.1 Playing Media............................................ 249 12.2 Sound Effects............................................. 251 12.3 Video Streams............................................ 252 12.4 Capturing Images........................................... 253 12.5 Advanced Techniques........................................ 255 12.6 Summary............................................... 256 13 Networking 257 13.1 Serving UI via HTTP......................................... 257 13.2 Templating.............................................. 260 13.3 HTTP Requests............................................ 260 13.4 Local files.............................................. 263 13.5 REST API.............................................. 264 13.6 Authentication using OAuth..................................... 269 ii 13.7 Web Sockets............................................. 270 13.8 Summary............................................... 276 14 Storage 277 14.1 Settings................................................ 277 14.2 Local Storage - SQL......................................... 278 14.3 Other Storage APIs.......................................... 282 15 Dynamic QML 283 15.1 Loading Components Dynamically................................. 283 15.2 Creating and Destroying Objects................................... 288 15.3 Tracking Dynamic Objects...................................... 291 15.4 Summary............................................... 293 16 JavaScript 295 16.1 Browser/HTML vs QtQuick/QML.................................. 296 16.2 The Language............................................ 296 16.3 JS Objects.............................................. 298 16.4 Creating a JS Console........................................ 299 17 Qt and C++ 305 17.1 A Boilerplate Application...................................... 306 17.2 The QObject............................................. 309 17.3 Build Systems............................................ 311 17.4 Common Qt Classes......................................... 314 17.5 Models in C++............................................ 319 18 Extending QML with C++ 329 18.1 Understanding the QML Run-time.................................. 329 18.2 Plugin Content............................................ 331 18.3 Creating the plugin.......................................... 332 18.4 FileIO Implementation........................................ 333 18.5 Using FileIO............................................. 334 18.6 Summary............................................... 340 19 Felgo Plugins and QML Hot Reloading 343 19.1 Tooling................................................ 343 19.2 Felgo Plugins............................................. 349 19.3 Monetization, Ads and In-App Purchases.............................. 351 19.4 Notifications............................................. 354 19.5 Analytics and Crash Reporting.................................... 357 19.6 Firebase: Authentication, Databases, and Storage.......................... 358 19.7 Cloud Storage, Augmented Reality, and More............................ 361 19.8 Felgo & WebAssembly........................................ 361 19.9 Summary............................................... 361 20 Qt for Python 363 20.1 Introduction............................................. 363 20.2 Installing............................................... 363 20.3 Building an Application....................................... 364 20.4 Limitations.............................................. 375 20.5 Summary............................................... 376 21 Offline Books 377 22 Source Code Examples 379 22.1 Testing................................................ 379 22.2 Deploying QML Applications.................................... 380 22.3 Drag and Drop............................................ 380 iii Index 381 iv Qt5 Cadaques, Release master Last Build: December 07, 2020 at 10:50 CET Welcome to the online book of Qt5 Cadaques! Why Qt5? Because Qt5 is awesome! Why Cadaques? Because one of the authors had a great holiday in this rocky coastline in the north-east of Spain. The entire collection of chapters covering Qt5 programming, written by Jürgen Bocklage-Ryannel and Johan Thelin, is available here. All book content is licensed under the Creative Commons Attribution Non-Commercial Share Alike 4.0 license and examples are licensed under the BSD license. Personal Note Jürgen Ryannel, the lead author has stopped working in his normal job and is bootstrapping a new company called ApiGear, which is all about API architectures. While the company is slowly forming, Jürgen is available for freelancing, ideally in the area of UI creating using QML or UI Architecture coaching. You can reach him via LinkedIn. / jryannel