Skip to Content
Hands-On GUI Programming with C++ and Qt5
book

Hands-On GUI Programming with C++ and Qt5

by Lee Zhi Eng
April 2018
Intermediate to advanced
404 pages
8h 27m
English
Packt Publishing
Content preview from Hands-On GUI Programming with C++ and Qt5

Obtaining a user's location

Qt provides us with a set of functions to retrieve a user's location information, but it will only work if the user's device supports geopositioning. This should work on all modern smartphones and might work on some of the modern computers as well.

To obtain the user's location using the Qt Location module, first let's open up mainwindow.h and add the following header files:

#include <QDebug> 
#include <QGeoPositionInfo> 
#include <QGeoPositionInfoSource> 

After that, declare the following slot function in the same file:

private slots: 
   void positionUpdated(const QGeoPositionInfo &info); 

Right after that, open up mainwindow.cpp and add the following code to the place where you want it to start getting the user's ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

C++ GUI Programming with Qt 4

C++ GUI Programming with Qt 4

Jasmin Blanchette, Mark Summerfield

Publisher Resources

ISBN: 9781788397827Supplemental Content