Qt5 Cadaques Release 2017-12
Total Page:16
File Type:pdf, Size:1020Kb
Qt5 Cadaques Release 2017-12 JRyannel,JThelin Januar 26, 2018 at 22:39 CET Inhaltsverzeichnis 1 Meet Qt 5 3 1.1 Preface................................................3 1.2 Qt 5 Introduction...........................................4 1.3 Qt Building Blocks..........................................8 1.4 Qt Project............................................... 10 2 Get Started 11 2.1 Installing Qt 5 SDK......................................... 11 2.2 Hello World............................................. 11 2.3 Application Types.......................................... 13 2.4 Summary............................................... 21 3 Qt Creator IDE 23 3.1 The User Interface.......................................... 23 3.2 Registering your Qt Kit....................................... 24 3.3 Managing Projects.......................................... 24 3.4 Using the Editor........................................... 25 3.5 Locator................................................ 25 3.6 Debugging.............................................. 26 3.7 Shortcuts............................................... 26 4 Quick Starter 27 4.1 QML Syntax............................................. 27 4.2 Basic Elements............................................ 32 4.3 Components............................................. 36 4.4 Simple Transformations....................................... 39 4.5 Positioning Elements......................................... 42 4.6 Layout Items............................................. 46 4.7 Input Elements............................................ 49 4.8 Advanced Techniques........................................ 53 5 Fluid Elements 55 5.1 Animations.............................................. 55 5.2 States and Transitions........................................ 70 5.3 Advanced Techniques........................................ 74 6 Model-View-Delegate 75 6.1 Concept................................................ 75 6.2 Basic Models............................................. 76 6.3 Dynamic Views............................................ 80 6.4 Delegate............................................... 89 6.5 Advanced Techniques........................................ 96 6.6 Summary............................................... 105 i 7 Canvas Element 107 7.1 Convenient API........................................... 109 7.2 Gradients............................................... 110 7.3 Shadows............................................... 111 7.4 Images................................................ 112 7.5 Transformation............................................ 113 7.6 Composition Modes......................................... 114 7.7 Pixel Buffers............................................. 115 7.8 Canvas Paint............................................. 116 7.9 Porting from HTML5 Canvas.................................... 118 8 Particle Simulations 125 8.1 Concept................................................ 125 8.2 Simple Simulation.......................................... 125 8.3 Particle Parameters.......................................... 128 8.4 Directed Particles........................................... 129 8.5 Particle Painters........................................... 132 8.6 Affecting Particles.......................................... 134 8.7 Particle Groups............................................ 138 8.8 Summary............................................... 145 9 Shader Effects 147 9.1 OpenGL Shaders........................................... 147 9.2 Shader Elements........................................... 148 9.3 Fragment Shaders.......................................... 150 9.4 Wave Effect.............................................. 154 9.5 Vertex Shader............................................. 156 9.6 Curtain Effect............................................ 164 9.7 Qt GraphicsEffect Library...................................... 167 10 Multimedia 171 10.1 Playing Media............................................ 171 10.2 Sound Effects............................................. 173 10.3 Video Streams............................................ 174 10.4 Capturing Images........................................... 175 10.5 Advanced Techniques........................................ 177 10.6 Summary............................................... 178 11 Networking 179 11.1 Serving UI via HTTP......................................... 179 11.2 Templating.............................................. 182 11.3 HTTP Requests............................................ 182 11.4 Local files.............................................. 185 11.5 REST API.............................................. 186 11.6 Authentication using OAuth..................................... 191 11.7 Engin IO............................................... 192 11.8 Web Sockets............................................. 192 11.9 Summary............................................... 197 12 Storage 199 12.1 Settings................................................ 199 12.2 Local Storage - SQL......................................... 200 12.3 Other Storage APIs.......................................... 204 13 Dynamic QML 205 13.1 Loading Components Dynamically................................. 205 13.2 Creating and Destroying Objects................................... 209 13.3 Tracking Dynamic Objects...................................... 212 13.4 Summary............................................... 214 ii 14 JavaScript 215 14.1 Browser/HTML vs QtQuick/QML.................................. 216 14.2 The Language............................................ 216 14.3 JS Objects.............................................. 218 14.4 Creating a JS Console........................................ 219 15 Qt and C++ 223 15.1 A Boilerplate Application...................................... 224 15.2 The QObject............................................. 227 15.3 Build Systems............................................ 229 15.4 Common Qt Classes......................................... 232 15.5 Models in C++............................................ 237 16 Extending QML with C++ 247 16.1 Understanding the QML Run-time.................................. 247 16.2 Plugin Content............................................ 249 16.3 Creating the plugin.......................................... 250 16.4 FileIO Implementation........................................ 251 16.5 Using FileIO............................................. 252 16.6 Summary............................................... 259 17 Assets 261 17.1 Offline Books............................................. 261 17.2 Source Code Examples........................................ 261 iii iv Qt5 Cadaques, Release 2017-12 Last Build: Januar 26, 2018 at 22:39 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 coast line in the north-east of spain. The entire collection of chapters covering Qt5 programming, written by Juergen 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. We are heavily working on this book and that means several things: 1. It’s not done. We will be releasing new chapters from time to time and updating existing chapters on the go. 2. We love your support. If you find any errors or have suggestions, please use our feedback system (the links). It will create a new ticket-entry in our ticket system and help us to keep track. 3. Be patient. We are working in our spare time on the book and we depend on the support of our companies and family. Enjoy! Content Inhaltsverzeichnis 1 Qt5 Cadaques, Release 2017-12 2 Inhaltsverzeichnis KAPITEL 1 Meet Qt 5 Autor des Abschnitts: jryannel Bemerkung: The source code of this chapter can be found in the assets folder. This book shall provide you a walk through the different aspect of application development using Qt version 5.x. It focuses on the new Qt Quick technology but also provides necessary information of writing C++ back-ends and extension for Qt Quick. This chapter provides a high level overview of Qt 5. It shows the different application models available for devel- opers and a Qt 5 showcase application to get a sneak preview of things to come. Additionally the chapter aims to provide a wide overview of the Qt 5 content and how to get in touch with the makers of Qt 5. Preface History Qt 4 has evolved since 2005 and provided a solid ground for thousands of applications and even full desktop and mobile systems. The usage patterns of computer users changed in the recent years. From stationary PCs towards portable notebook and nowadays mobile computers. The classical desktop is more and more replaced with mobile touch-based always connected screens. With it the desktop UX paradigms also changes. Where as in the past Windows UI has dominated the world we spend more time nowadays on other screens with another UI language. Qt 4 was designed to satisfy the desktop world to have a coherent set of UI widgets available on all major platforms. The challenge for Qt users has changed today and it lies more to provide a touch-based user interface for a customer driven user interface and to enable modern user interface on all major desktop and mobile systems. Qt 4.7 started to introduce the Qt Quick technology which allows users to