Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
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

Accessing sensors with C++

So far, we have learned how we can access the sensors' data through QML scripting. However, the sensors can also be accessed through Qt's various C++ classes. We will walk through some examples of this and demonstrate how we can achieve that.

First, create an empty Qt project (you can continue from the previous example if you wish, though). Instead of writing the code in the .qml file, we will open up main.cpp instead. After that, we will include some headers so that we can access these classes. Remember to add the sensors module to your project file (.pro) if you are creating a new Qt project:

#include <QDebug>
#include <QTimer>

#include <QAccelerometer>
#include <QAmbientLightSensor>
#include <QProximitySensor>

#include <QAccelerometerReading>
#include <QAmbientLightReading>
#include <QProximityReading...
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 $19.99/month. Cancel anytime
Banner background image