5#include "../qgeoerror_messages.h"
7#include <QCoreApplication>
8#include <QtCore/QJsonDocument>
9#include <QtCore/QJsonObject>
10#include <QtCore/QJsonArray>
19 setError(UnknownError, QStringLiteral(
"Null reply"));
22 connect(reply, &QNetworkReply::finished,
23 this, &QPlaceSearchSuggestionReplyImpl::replyFinished);
24 connect(reply, &QNetworkReply::errorOccurred,
25 this, &QPlaceSearchSuggestionReplyImpl::replyError);
26 connect(
this, &QPlaceReply::aborted, reply, &QNetworkReply::abort);
27 connect(
this, &QObject::destroyed, reply, &QObject::deleteLater);
30QPlaceSearchSuggestionReplyImpl::~QPlaceSearchSuggestionReplyImpl()
34void QPlaceSearchSuggestionReplyImpl::setError(QPlaceReply::Error error_,
35 const QString &errorString)
37 QPlaceReply::setError(error_, errorString);
38 emit errorOccurred(error_, errorString);
43void QPlaceSearchSuggestionReplyImpl::replyFinished()
45 QNetworkReply *reply =
static_cast<QNetworkReply *>(sender());
48 if (reply->error() != QNetworkReply::NoError)
51 QJsonDocument document = QJsonDocument::fromJson(reply->readAll());
52 if (!document.isObject()) {
53 setError(ParseError, QCoreApplication::translate(NOKIA_PLUGIN_CONTEXT_NAME, PARSE_ERROR));
54 emit errorOccurred(error(), errorString());
58 QJsonObject object = document.object();
60 QJsonArray suggestions = object.value(QStringLiteral(
"suggestions")).toArray();
63 for (
int i = 0; i < suggestions.count(); ++i) {
64 QJsonValue v = suggestions.at(i);
66 s.append(v.toString());
75void QPlaceSearchSuggestionReplyImpl::replyError(QNetworkReply::NetworkError error)
77 QNetworkReply *reply =
static_cast<QNetworkReply *>(sender());
79 if (error == QNetworkReply::OperationCanceledError)
80 setError(QPlaceReply::CancelError, QCoreApplication::translate(NOKIA_PLUGIN_CONTEXT_NAME, CANCEL_ERROR));
82 setError(QPlaceReply::CommunicationError, QCoreApplication::translate(NOKIA_PLUGIN_CONTEXT_NAME, NETWORK_ERROR));
The QNetworkReply class contains the data and headers for a request sent with QNetworkAccessManager.
Combined button and popup list for selecting options.