Qt
Internal/Contributor docs for the Qt SDK. <b>Note:</b> These are NOT official API docs; those are found <a href='https://doc.qt.io/'>here</a>.
Loading...
Searching...
No Matches
qplacesearchsuggestionreplyimpl.cpp
Go to the documentation of this file.
1// Copyright (C) 2015 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3
6
7#include <QCoreApplication>
8#include <QtCore/QJsonDocument>
9#include <QtCore/QJsonObject>
10#include <QtCore/QJsonArray>
11
13
15 QObject *parent)
17{
18 if (!reply) {
19 setError(UnknownError, QStringLiteral("Null reply"));
20 return;
21 }
23 this, &QPlaceSearchSuggestionReplyImpl::replyFinished);
25 this, &QPlaceSearchSuggestionReplyImpl::replyError);
28}
29
33
34void QPlaceSearchSuggestionReplyImpl::setError(QPlaceReply::Error error_,
35 const QString &errorString)
36{
39 setFinished(true);
40 emit finished();
41}
42
43void QPlaceSearchSuggestionReplyImpl::replyFinished()
44{
45 QNetworkReply *reply = static_cast<QNetworkReply *>(sender());
47
49 return;
50
52 if (!document.isObject()) {
55 return;
56 }
57
58 QJsonObject object = document.object();
59
60 QJsonArray suggestions = object.value(QStringLiteral("suggestions")).toArray();
61
63 for (int i = 0; i < suggestions.count(); ++i) {
65 if (v.isString())
66 s.append(v.toString());
67 }
68
70
71 setFinished(true);
72 emit finished();
73}
74
75void QPlaceSearchSuggestionReplyImpl::replyError(QNetworkReply::NetworkError error)
76{
77 QNetworkReply *reply = static_cast<QNetworkReply *>(sender());
81 else
83}
84
static QString translate(const char *context, const char *key, const char *disambiguation=nullptr, int n=-1)
\threadsafe
QByteArray readAll()
Reads all remaining data from the device, and returns it as a byte array.
\inmodule QtCore\reentrant
Definition qjsonarray.h:18
\inmodule QtCore\reentrant
static QJsonDocument fromJson(const QByteArray &json, QJsonParseError *error=nullptr)
Parses json as a UTF-8 encoded JSON document, and creates a QJsonDocument from it.
\inmodule QtCore\reentrant
Definition qjsonobject.h:20
\inmodule QtCore\reentrant
Definition qjsonvalue.h:25
The QNetworkReply class contains the data and headers for a request sent with QNetworkAccessManager.
void errorOccurred(QNetworkReply::NetworkError)
NetworkError error() const
Returns the error that was found during the processing of this request.
virtual void abort()=0
Aborts the operation immediately and close down any network connections still open.
NetworkError
Indicates all possible error conditions found during the processing of the request.
void finished()
This signal is emitted when the reply has finished processing.
\inmodule QtCore
Definition qobject.h:103
static QMetaObject::Connection connect(const QObject *sender, const char *signal, const QObject *receiver, const char *member, Qt::ConnectionType=Qt::AutoConnection)
\threadsafe
Definition qobject.cpp:2960
QObject * sender() const
Returns a pointer to the object that sent the signal, if called in a slot activated by a signal; othe...
Definition qobject.cpp:2658
void destroyed(QObject *=nullptr)
This signal is emitted immediately before the object obj is destroyed, after any instances of QPointe...
void deleteLater()
\threadsafe
Definition qobject.cpp:2435
QPlaceReply::Error error() const
Returns the error code.
void errorOccurred(QPlaceReply::Error error, const QString &errorString=QString())
This signal is emitted when an error has been detected in the processing of this reply.
void finished()
This signal is emitted when this reply has finished processing.
Error
Describes an error which occurred during an operation.
Definition qplacereply.h:18
void aborted()
QString errorString() const
Returns the error string of the reply.
void setError(QPlaceReply::Error error, const QString &errorString)
Sets the error and errorString of the reply.
void setFinished(bool finished)
Sets the status of whether the reply is finished or not.
QPlaceSearchSuggestionReplyImpl(QNetworkReply *reply, QObject *parent=nullptr)
void setSuggestions(const QStringList &suggestions)
Sets the search term suggestions.
QStringList suggestions() const
Returns the search term suggestions.
\inmodule QtCore
\macro QT_RESTRICTED_CAST_FROM_ASCII
Definition qstring.h:129
Combined button and popup list for selecting options.
emscripten::val document()
Definition qwasmdom.h:49
DBusConnection const char DBusError * error
QT_BEGIN_NAMESPACE const char NOKIA_PLUGIN_CONTEXT_NAME[]
const char PARSE_ERROR[]
const char CANCEL_ERROR[]
const char NETWORK_ERROR[]
GLsizei const GLfloat * v
[13]
GLdouble s
[6]
Definition qopenglext.h:235
#define QStringLiteral(str)
#define emit
QNetworkReply * reply