Can I get user location on a Qt Desktop application?

  • I read that the OS X can get the approximate user location using the Wi-Fi network.

    Can I get the approximate user location on a Qt Desktop application?

    I tried to add Qt += positioning to my .pro file and use the following code:

        QGeoPositionInfoSource *source1 = QGeoPositionInfoSource::createDefaultSource(this);
        if (source1)
            qDebug() << "Test1";
        QGeoAreaMonitorSource *source2 = QGeoAreaMonitorSource::createDefaultSource(this);
        if (source2)
            qDebug() << "Test2";
        QGeoSatelliteInfoSource *source3 = QGeoSatelliteInfoSource::createDefaultSource(this);
        if (source3)
            qDebug() << "Test3";

    But no source (source1, source2, source3) is valid.

    Basically, I need to get the user location (latitude and longitude) to calculate the sunrise and sunset time.

    Note 1: the application will run on Windows and OS X.

    Note 2: I'm currently running it on a Macbook Pro with internet connection (don't know if it matters).


  • Lifetime Qt Champion


    You should start by running one of the example from the module.

    IIRC, on macOS you should get a dialog asking whether you allow the application to get the position information from your machine.

Log in to reply

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.