Search icon CANCEL
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Conferences
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
Application Development with Qt Creator

You're reading from   Application Development with Qt Creator Build cross-platform applications and GUIs using Qt 5 and C++

Arrow left icon
Product type Paperback
Published in Jan 2020
Publisher
ISBN-13 9781789951752
Length 426 pages
Edition 3rd Edition
Languages
Tools
Arrow right icon
Author (1):
Arrow left icon
Lee Zhi Eng Lee Zhi Eng
Author Profile Icon Lee Zhi Eng
Lee Zhi Eng
Arrow right icon
View More author details
Toc

Table of Contents (19) Chapters Close

Preface 1. Section 1: The Basics
2. Getting Started with Qt Creator FREE CHAPTER 3. Building Applications with Qt Creator 4. Designing Your Application with Qt Designer 5. Qt Foundations 6. Developing Applications with Qt Widgets 7. Section 2: Advanced Features
8. Drawing with Qt 9. Doing More with Qt Quick 10. Implementing Multimedia with Qt Quick 11. Sensors and Qt Quick 12. Section 3: Practical Matters
13. Localizing Your Application with Qt Linguist 14. Optimizing Performance with Qt Creator 15. Developing Mobile Applications with Qt Creator 16. Embedded and IoT Development with Qt Creator 17. Qt Tips and Tricks 18. Other Books You May Enjoy

Obtaining a device's position

Let's move on to a simple example that returns the device's position, accelerometer, gyroscope, ambient light, and magnetometer readings. Here's what our application looks like when running on a Huawei phone:

Note that my Huawei phone does not have a magnetometer, so these readings aren't being updated. Let's see how this works:

  1. First, we need to ensure that we include the positioning and sensor modules in our .pro file (if we don't, the application will compile but fail to launch):
QT += quick positioning sensors 
  1. Next, we'll move on to the QML itself. This is long but straightforward. First, we add the necessary modules to our project; then, we define the Window object for our program:
import QtQuick 2.12
import QtQuick.Window 2.12
import QtPositioning 5.12
import QtSensors 5.12

Window {
visible: true...
lock icon The rest of the chapter is locked
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at R$50/month. Cancel anytime