创建QGeoAddress以获取LNK2019

creating QGeoAddress getting a LNK2019

本文关键字:LNK2019 获取 QGeoAddress 创建      更新时间:2023-10-16

我想用C++对地址进行地理编码,并想使用QtLocation和Qt定位功能。我认为第一步是创建一个QGeoAddress。但这并不奏效。我收到LNK2019故障。如果你能帮我就太好了!

#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;
}

错误消息是(很抱歉是德语):

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".
debugRegex_GeoModA_Qt.exe : fatal error LNK1120: 2 nicht aufgelöste Externe
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();

}

这段代码需要额外的QJson对象库。

您可以从这里下载源代码并进行编译和使用。