0

I want to geocode addresses with C++ and wanted to use the QtLocation and Qtpositioning stuff. I thought the first step was to create a QGeoAddress. But this does not work. I'm getting a LNK2019 failure. It would be great if you could help me!

#include <QCoreApplication>
#include <iostream>
#include <iomanip>
#include <fstream>
#include <regex>
#include <string>
#include <streambuf>
#include <QtPositioning/QGeoAddress.h>
#include <QtPositioning/QGeoLocation>
#include <QtLocation/QGeoCodingManager>
#include <QtLocation/QGeoServiceProvider>
#include <QString>
#include <QtLocation/QGeoCodeReply>

using namespace std;

int main(int argc, char *argv[])
{
    QCoreApplication a(argc, argv);
    QGeoAddress searchAddress;
}

The error message is (I'm sorry that it is in german):

main.obj : error LNK2019: Verweis auf nicht aufgelöstes externes Symbol ""__declspec(dllimport) public: __cdecl QGeoAddress::QGeoAddress(void)" (__imp_??0QGeoAddress@@QEAA@XZ)" in Funktion "main".
main.obj : error LNK2019: Verweis auf nicht aufgelöstes externes Symbol ""__declspec(dllimport) public: __cdecl QGeoAddress::~QGeoAddress(void)" (__imp_??1QGeoAddress@@QEAA@XZ)" in Funktion "main".
debug\Regex_GeoModA_Qt.exe : fatal error LNK1120: 2 nicht aufgelöste Externe
Paraboloid87
  • 428
  • 2
  • 14
peggers
  • 31
  • 6
  • Post the entire error message, please. – Dan Mašek Apr 29 '16 at 10:43
  • ok, i added it. I hope it helps – peggers Apr 29 '16 at 10:48
  • Looks to me that you forgot to link with `Qt5Positioning` library. That's why it says that there's a reference to unresolved external. – Dan Mašek Apr 29 '16 at 10:53
  • See [this answer](http://stackoverflow.com/a/20059167/3962537), since it seems you're asking about MS Visual C++. – Dan Mašek Apr 29 '16 at 11:02
  • I use Qt Creator with a MS Visual C++ compiler. I'll try to figure out how it works – peggers Apr 29 '16 at 11:05
  • This is my .pro file. Do I have to include it there? `QT += core QT += positioning QT += location QT -= gui CONFIG += c++11 TARGET = Regex_GeoModA_Qt CONFIG += console CONFIG -= app_bundle TEMPLATE = app SOURCES += main.cpp` – peggers Apr 29 '16 at 11:07
  • I don't know about that, sorry. I'm familiar with MSVS, but I don't use Qt. However, based on the [docs](http://doc.qt.io/qt-5/qtpositioning-index.html) that seems to be the case. – Dan Mašek Apr 29 '16 at 11:23

1 Answers1

-1
QNetworkAccessManager* manager = new QNetworkAccessManager;

connect(manager, SIGNAL(finished(QNetworkReply*)), SLOT(fReply(QNetworkReply*)));

    QString url = QString("http://maps.google.com/maps/api/geocode/json?address=%1&sensor=false&language=en").arg(your_address);

    manager->get(QNetworkRequest(QUrl(url)));





void fReply(QNetworkReply *reply)
{

    QString json = reply->readAll();
    QString strUrl = reply->url().toString();

    QJson::Parser parser;

    bool ok;

    // json is a QString containing the data to convert
    //QVariant result = parser.parse (json.toLatin1(), &ok);
    QVariant result = parser.parse (json.toLatin1(), &ok);
    if(!ok)
    {
        qDebug()<< (QString("HATA : Cannot convert to QJson object: %1").arg(json));
        return;
    }

    QString code = result.toMap()["status"].toString();
    qDebug() << "Code" << code;
    if(code != "OK")
    {
        qDebug() << (QString("HATA : Code of request is: %1").arg(code));
        return;
    }

    QVariantList results = result.toMap()["results"].toList();
    if(results.count() == 0)
    {
        qDebug() << (QString("HATA : Cannot find any locations"));
        return;
    }

    double east  = results[0].toMap()["geometry"].toMap()["location"].toMap()["lng"].toDouble();
    double north = results[0].toMap()["geometry"].toMap()["location"].toMap()["lat"].toDouble();


}

this code need to extra library that QJson Object.

you can download source code from here and compile and use it.

CMLDMR
  • 334
  • 2
  • 12