Qt 4.8
Public Types | Public Functions | Private Types | Private Slots | Private Functions | Properties | List of all members
QDeclarativeXMLHttpRequest Class Reference
Inheritance diagram for QDeclarativeXMLHttpRequest:
QObject

Public Types

enum  State {
  Unsent = 0, Opened = 1, HeadersReceived = 2, Loading = 3,
  Done = 4
}
 

Public Functions

QScriptValue abort (QScriptValue *me)
 
void addHeader (const QString &, const QString &)
 
bool errorFlag () const
 
QString header (const QString &name)
 
QString headers ()
 
QScriptValue open (QScriptValue *me, const QString &, const QUrl &)
 
 QDeclarativeXMLHttpRequest (QNetworkAccessManager *manager)
 
const QByteArrayrawResponseBody () const
 
quint32 readyState () const
 
bool receivedXml () const
 
int replyStatus () const
 
QString replyStatusText () const
 
QString responseBody ()
 
QScriptValue send (QScriptValue *me, const QByteArray &)
 
bool sendFlag () const
 
virtual ~QDeclarativeXMLHttpRequest ()
 
- Public Functions inherited from QObject
bool blockSignals (bool b)
 If block is true, signals emitted by this object are blocked (i.e., emitting a signal will not invoke anything connected to it). More...
 
const QObjectListchildren () const
 Returns a list of child objects. More...
 
bool connect (const QObject *sender, const char *signal, const char *member, Qt::ConnectionType type=Qt::AutoConnection) const
 
bool disconnect (const char *signal=0, const QObject *receiver=0, const char *member=0)
 
bool disconnect (const QObject *receiver, const char *member=0)
 
void dumpObjectInfo ()
 Dumps information about signal connections, etc. More...
 
void dumpObjectTree ()
 Dumps a tree of children to the debug output. More...
 
QList< QByteArraydynamicPropertyNames () const
 Returns the names of all properties that were dynamically added to the object using setProperty(). More...
 
virtual bool event (QEvent *)
 This virtual function receives events to an object and should return true if the event e was recognized and processed. More...
 
virtual bool eventFilter (QObject *, QEvent *)
 Filters events if this object has been installed as an event filter for the watched object. More...
 
template<typename T >
findChild (const QString &aName=QString()) const
 Returns the child of this object that can be cast into type T and that is called name, or 0 if there is no such object. More...
 
template<typename T >
QList< T > findChildren (const QString &aName=QString()) const
 Returns all children of this object with the given name that can be cast to type T, or an empty list if there are no such objects. More...
 
template<typename T >
QList< T > findChildren (const QRegExp &re) const
 
bool inherits (const char *classname) const
 Returns true if this object is an instance of a class that inherits className or a QObject subclass that inherits className; otherwise returns false. More...
 
void installEventFilter (QObject *)
 Installs an event filter filterObj on this object. More...
 
bool isWidgetType () const
 Returns true if the object is a widget; otherwise returns false. More...
 
void killTimer (int id)
 Kills the timer with timer identifier, id. More...
 
virtual const QMetaObjectmetaObject () const
 Returns a pointer to the meta-object of this object. More...
 
void moveToThread (QThread *thread)
 Changes the thread affinity for this object and its children. More...
 
QString objectName () const
 
QObjectparent () const
 Returns a pointer to the parent object. More...
 
QVariant property (const char *name) const
 Returns the value of the object's name property. More...
 
Q_INVOKABLE QObject (QObject *parent=0)
 Constructs an object with parent object parent. More...
 
void removeEventFilter (QObject *)
 Removes an event filter object obj from this object. More...
 
void setObjectName (const QString &name)
 
void setParent (QObject *)
 Makes the object a child of parent. More...
 
bool setProperty (const char *name, const QVariant &value)
 Sets the value of the object's name property to value. More...
 
void setUserData (uint id, QObjectUserData *data)
 
bool signalsBlocked () const
 Returns true if signals are blocked; otherwise returns false. More...
 
int startTimer (int interval)
 Starts a timer and returns a timer identifier, or returns zero if it could not start a timer. More...
 
QThreadthread () const
 Returns the thread in which the object lives. More...
 
QObjectUserDatauserData (uint id) const
 
virtual ~QObject ()
 Destroys the object, deleting all its child objects. More...
 

Private Types

typedef QPair< QByteArray, QByteArrayHeaderPair
 
typedef QList< HeaderPairHeadersList
 

Private Slots

void downloadProgress (qint64)
 
void error (QNetworkReply::NetworkError)
 
void finished ()
 

Private Functions

void destroyNetwork ()
 
QScriptValue dispatchCallback (QScriptValue *me)
 
void fillHeadersList ()
 
QTextCodecfindTextCodec () const
 
QNetworkAccessManagernetworkAccessManager ()
 
void printError (const QScriptValue &)
 
void readEncoding ()
 
void requestFromUrl (const QUrl &url)
 

Properties

QByteArray m_charset
 
QByteArray m_data
 
bool m_errorFlag
 
bool m_gotXml
 
HeadersList m_headersList
 
QScriptValue m_me
 
QString m_method
 
QByteArray m_mime
 
QNetworkAccessManagerm_nam
 
QDeclarativeGuard< QNetworkReplym_network
 
int m_redirectCount
 
QNetworkRequest m_request
 
QByteArray m_responseEntityBody
 
bool m_sendFlag
 
State m_state
 
int m_status
 
QString m_statusText
 
QTextCodecm_textCodec
 
QUrl m_url
 

Additional Inherited Members

- Public Slots inherited from QObject
void deleteLater ()
 Schedules this object for deletion. More...
 
- Signals inherited from QObject
void destroyed (QObject *=0)
 This signal is emitted immediately before the object obj is destroyed, and can not be blocked. More...
 
- Static Public Functions inherited from QObject
static bool connect (const QObject *sender, const char *signal, const QObject *receiver, const char *member, Qt::ConnectionType=Qt::AutoConnection)
 Creates a connection of the given type from the signal in the sender object to the method in the receiver object. More...
 
static bool connect (const QObject *sender, const QMetaMethod &signal, const QObject *receiver, const QMetaMethod &method, Qt::ConnectionType type=Qt::AutoConnection)
 
static bool disconnect (const QObject *sender, const char *signal, const QObject *receiver, const char *member)
 Disconnects signal in object sender from method in object receiver. More...
 
static bool disconnect (const QObject *sender, const QMetaMethod &signal, const QObject *receiver, const QMetaMethod &member)
 
static uint registerUserData ()
 
static QString tr (const char *sourceText, const char *comment=0, int n=-1)
 
static QString trUtf8 (const char *sourceText, const char *comment=0, int n=-1)
 
- Static Public Variables inherited from QObject
static const QMetaObject staticMetaObject
 This variable stores the meta-object for the class. More...
 
- Protected Functions inherited from QObject
virtual void childEvent (QChildEvent *)
 This event handler can be reimplemented in a subclass to receive child events. More...
 
virtual void connectNotify (const char *signal)
 This virtual function is called when something has been connected to signal in this object. More...
 
virtual void customEvent (QEvent *)
 This event handler can be reimplemented in a subclass to receive custom events. More...
 
virtual void disconnectNotify (const char *signal)
 This virtual function is called when something has been disconnected from signal in this object. More...
 
 QObject (QObjectPrivate &dd, QObject *parent=0)
 
int receivers (const char *signal) const
 Returns the number of receivers connected to the signal. More...
 
QObjectsender () const
 Returns a pointer to the object that sent the signal, if called in a slot activated by a signal; otherwise it returns 0. More...
 
int senderSignalIndex () const
 
virtual void timerEvent (QTimerEvent *)
 This event handler can be reimplemented in a subclass to receive timer events for the object. More...
 
- Protected Variables inherited from QObject
QScopedPointer< QObjectDatad_ptr
 
- Static Protected Variables inherited from QObject
static const QMetaObject staticQtMetaObject
 

Detailed Description

Definition at line 945 of file qdeclarativexmlhttprequest.cpp.

Typedefs

◆ HeaderPair

Definition at line 990 of file qdeclarativexmlhttprequest.cpp.

◆ HeadersList

Definition at line 991 of file qdeclarativexmlhttprequest.cpp.

Enumerations

◆ State

Constructors and Destructors

◆ QDeclarativeXMLHttpRequest()

QDeclarativeXMLHttpRequest::QDeclarativeXMLHttpRequest ( QNetworkAccessManager manager)

◆ ~QDeclarativeXMLHttpRequest()

QDeclarativeXMLHttpRequest::~QDeclarativeXMLHttpRequest ( )
virtual

Definition at line 1025 of file qdeclarativexmlhttprequest.cpp.

1026 {
1027  destroyNetwork();
1028 }

Functions

◆ abort()

QScriptValue QDeclarativeXMLHttpRequest::abort ( QScriptValue me)

Definition at line 1190 of file qdeclarativexmlhttprequest.cpp.

Referenced by qmlxmlhttprequest_abort().

1191 {
1192  destroyNetwork();
1194  m_errorFlag = true;
1196 
1197  if (!(m_state == Unsent ||
1198  (m_state == Opened && !m_sendFlag) ||
1199  m_state == Done)) {
1200 
1201  m_state = Done;
1202  m_sendFlag = false;
1203  QScriptValue cbv = dispatchCallback(me);
1204  if (cbv.isError()) return cbv;
1205  }
1206 
1207  m_state = Unsent;
1208  return QScriptValue();
1209 }
bool isError() const
Returns true if this QScriptValue is an object of the Error class; otherwise returns false...
The QByteArray class provides an array of bytes.
Definition: qbytearray.h:135
QScriptValue dispatchCallback(QScriptValue *me)
The QNetworkRequest class holds a request to be sent with QNetworkAccessManager.
The QScriptValue class acts as a container for the Qt Script data types.
Definition: qscriptvalue.h:57

◆ addHeader()

void QDeclarativeXMLHttpRequest::addHeader ( const QString name,
const QString value 
)

Definition at line 1067 of file qdeclarativexmlhttprequest.cpp.

Referenced by qmlxmlhttprequest_setRequestHeader().

1068 {
1069  QByteArray utfname = name.toUtf8();
1070 
1071  if (m_request.hasRawHeader(utfname)) {
1072  m_request.setRawHeader(utfname, m_request.rawHeader(utfname) + ',' + value.toUtf8());
1073  } else {
1074  m_request.setRawHeader(utfname, value.toUtf8());
1075  }
1076 }
bool hasRawHeader(const QByteArray &headerName) const
Returns true if the raw header headerName is present in this network request.
QByteArray rawHeader(const QByteArray &headerName) const
Returns the raw form of header headerName.
QByteArray toUtf8() const Q_REQUIRED_RESULT
Returns a UTF-8 representation of the string as a QByteArray.
Definition: qstring.cpp:4074
The QByteArray class provides an array of bytes.
Definition: qbytearray.h:135
void setRawHeader(const QByteArray &headerName, const QByteArray &value)
Sets the header headerName to be of value headerValue.

◆ destroyNetwork()

void QDeclarativeXMLHttpRequest::destroyNetwork ( )
private

Definition at line 1413 of file qdeclarativexmlhttprequest.cpp.

Referenced by abort(), error(), finished(), open(), and ~QDeclarativeXMLHttpRequest().

1414 {
1415  if (m_network) {
1416  m_network->disconnect();
1418  m_network = 0;
1419  }
1420 }
QDeclarativeGuard< QNetworkReply > m_network
static bool disconnect(const QObject *sender, const char *signal, const QObject *receiver, const char *member)
Disconnects signal in object sender from method in object receiver.
Definition: qobject.cpp:2895
void deleteLater()
Schedules this object for deletion.
Definition: qobject.cpp:2145

◆ dispatchCallback()

QScriptValue QDeclarativeXMLHttpRequest::dispatchCallback ( QScriptValue me)
private

Definition at line 1400 of file qdeclarativexmlhttprequest.cpp.

Referenced by abort(), downloadProgress(), error(), finished(), and open().

1401 {
1402  QScriptValue v = me->property(QLatin1String("callback"));
1403  return v.call();
1404 }
QScriptValue property(const QString &name, const ResolveFlags &mode=ResolvePrototype) const
Returns the value of this QScriptValue&#39;s property with the given name, using the given mode to resolv...
QLatin1String(DBUS_INTERFACE_DBUS))) Q_GLOBAL_STATIC_WITH_ARGS(QString
The QScriptValue class acts as a container for the Qt Script data types.
Definition: qscriptvalue.h:57
QScriptValue call(const QScriptValue &thisObject=QScriptValue(), const QScriptValueList &args=QScriptValueList())
Calls this QScriptValue as a function, using thisObject as the `this&#39; object in the function call...

◆ downloadProgress

void QDeclarativeXMLHttpRequest::downloadProgress ( qint64  bytes)
privateslot

Definition at line 1211 of file qdeclarativexmlhttprequest.cpp.

Referenced by requestFromUrl().

1212 {
1213  Q_UNUSED(bytes)
1214  m_status =
1216  m_statusText =
1218 
1219  // ### We assume if this is called the headers are now available
1220  if (m_state < HeadersReceived) {
1222  fillHeadersList ();
1224  if (cbv.isError()) printError(cbv);
1225  }
1226 
1227  bool wasEmpty = m_responseEntityBody.isEmpty();
1229  if (wasEmpty && !m_responseEntityBody.isEmpty()) {
1230  m_state = Loading;
1232  if (cbv.isError()) printError(cbv);
1233  }
1234 }
QByteArray & append(char c)
Appends the character ch to this byte array.
QVariant attribute(QNetworkRequest::Attribute code) const
Returns the attribute associated with the code code.
bool isError() const
Returns true if this QScriptValue is an object of the Error class; otherwise returns false...
QDeclarativeGuard< QNetworkReply > m_network
QByteArray toByteArray() const
Returns the variant as a QByteArray if the variant has type() ByteArray or String (converted using QS...
Definition: qvariant.cpp:2383
int toInt(bool *ok=0) const
Returns the variant as an int if the variant has type() Int , Bool , ByteArray , Char ...
Definition: qvariant.cpp:2625
void printError(const QScriptValue &)
static QString fromUtf8(const char *, int size=-1)
Returns a QString initialized with the first size bytes of the UTF-8 string str.
Definition: qstring.cpp:4302
QScriptValue dispatchCallback(QScriptValue *me)
QByteArray readAll()
Reads all available data from the device, and returns it as a QByteArray.
Definition: qiodevice.cpp:1025
bool isEmpty() const
Returns true if the byte array has size 0; otherwise returns false.
Definition: qbytearray.h:421
The QScriptValue class acts as a container for the Qt Script data types.
Definition: qscriptvalue.h:57
#define Q_UNUSED(x)
Indicates to the compiler that the parameter with the specified name is not used in the body of a fun...
Definition: qglobal.h:1729

◆ error

void QDeclarativeXMLHttpRequest::error ( QNetworkReply::NetworkError  error)
privateslot

Definition at line 1236 of file qdeclarativexmlhttprequest.cpp.

Referenced by printError(), and requestFromUrl().

1237 {
1238  Q_UNUSED(error)
1239  m_status =
1241  m_statusText =
1243 
1245 
1247  m_data.clear();
1248  destroyNetwork();
1249 
1255  m_state = Loading;
1257  if (cbv.isError()) printError(cbv);
1258  } else {
1259  m_errorFlag = true;
1260  }
1261 
1262  m_state = Done;
1264  if (cbv.isError()) printError(cbv);
1265 }
QVariant attribute(QNetworkRequest::Attribute code) const
Returns the attribute associated with the code code.
bool isError() const
Returns true if this QScriptValue is an object of the Error class; otherwise returns false...
The QByteArray class provides an array of bytes.
Definition: qbytearray.h:135
void error(QNetworkReply::NetworkError)
QDeclarativeGuard< QNetworkReply > m_network
QByteArray toByteArray() const
Returns the variant as a QByteArray if the variant has type() ByteArray or String (converted using QS...
Definition: qvariant.cpp:2383
int toInt(bool *ok=0) const
Returns the variant as an int if the variant has type() Int , Bool , ByteArray , Char ...
Definition: qvariant.cpp:2625
void printError(const QScriptValue &)
static QString fromUtf8(const char *, int size=-1)
Returns a QString initialized with the first size bytes of the UTF-8 string str.
Definition: qstring.cpp:4302
QScriptValue dispatchCallback(QScriptValue *me)
The QNetworkRequest class holds a request to be sent with QNetworkAccessManager.
The QScriptValue class acts as a container for the Qt Script data types.
Definition: qscriptvalue.h:57
#define Q_UNUSED(x)
Indicates to the compiler that the parameter with the specified name is not used in the body of a fun...
Definition: qglobal.h:1729
void clear()
Clears the contents of the byte array and makes it empty.

◆ errorFlag()

bool QDeclarativeXMLHttpRequest::errorFlag ( ) const

◆ fillHeadersList()

void QDeclarativeXMLHttpRequest::fillHeadersList ( )
private

Definition at line 1102 of file qdeclarativexmlhttprequest.cpp.

Referenced by downloadProgress(), and finished().

1103 {
1104  QList<QByteArray> headerList = m_network->rawHeaderList();
1105 
1106  m_headersList.clear();
1107  foreach (const QByteArray &header, headerList) {
1108  HeaderPair pair (header.toLower(), m_network->rawHeader(header));
1109  if (pair.first == "set-cookie" ||
1110  pair.first == "set-cookie2")
1111  continue;
1112 
1113  m_headersList << pair;
1114  }
1115 }
The QByteArray class provides an array of bytes.
Definition: qbytearray.h:135
QByteArray toLower() const
Returns a lowercase copy of the byte array.
QDeclarativeGuard< QNetworkReply > m_network
QList< QByteArray > rawHeaderList() const
Returns a list of headers fields that were sent by the remote server, in the order that they were sen...
void clear()
Removes all items from the list.
Definition: qlist.h:764
QPair< QByteArray, QByteArray > HeaderPair
QString header(const QString &name)
QByteArray rawHeader(const QByteArray &headerName) const
Returns the raw contents of the header headerName as sent by the remote server.

◆ findTextCodec()

QTextCodec * QDeclarativeXMLHttpRequest::findTextCodec ( ) const
private

Definition at line 1357 of file qdeclarativexmlhttprequest.cpp.

Referenced by responseBody().

1358 {
1359  QTextCodec *codec = 0;
1360 
1361  if (!m_charset.isEmpty())
1363 
1364  if (!codec && m_gotXml) {
1366  reader.readNext();
1367  codec = QTextCodec::codecForName(reader.documentEncoding().toString().toUtf8());
1368  }
1369 
1370  if (!codec && m_mime == "text/html")
1372 
1373  if (!codec)
1375 
1376  if (!codec)
1377  codec = QTextCodec::codecForName("UTF-8");
1378  return codec;
1379 }
static QTextCodec * codecForHtml(const QByteArray &ba)
Tries to detect the encoding of the provided snippet of HTML in the given byte array, ba, by checking the BOM (Byte Order Mark) and the content-type meta header and returns a QTextCodec instance that is capable of decoding the html to unicode.
static QTextCodec * codec(MYSQL *mysql)
Definition: qsql_mysql.cpp:220
static QTextCodec * codecForName(const QByteArray &name)
Searches all installed QTextCodec objects and returns the one which best matches name; the match is c...
static QTextCodec * codecForUtfText(const QByteArray &ba)
Tries to detect the encoding of the provided snippet ba by using the BOM (Byte Order Mark) and return...
bool isEmpty() const
Returns true if the byte array has size 0; otherwise returns false.
Definition: qbytearray.h:421
The QXmlStreamReader class provides a fast parser for reading well-formed XML via a simple streaming ...
Definition: qxmlstream.h:290
The QTextCodec class provides conversions between text encodings.
Definition: qtextcodec.h:62

◆ finished

void QDeclarativeXMLHttpRequest::finished ( )
privateslot

Definition at line 1268 of file qdeclarativexmlhttprequest.cpp.

Referenced by requestFromUrl().

1269 {
1270  m_redirectCount++;
1273  if (redirect.isValid()) {
1274  QUrl url = m_network->url().resolved(redirect.toUrl());
1275  if (url.scheme().toLower() != QLatin1String("file")) {
1276  // See http://www.ietf.org/rfc/rfc2616.txt, section 10.3.4 "303 See Other":
1277  // Result of 303 redirection should be a new "GET" request.
1279  if (code.isValid() && code.toInt() == 303 && m_method != QLatin1String("GET"))
1280  m_method = QLatin1String("GET");
1281  destroyNetwork();
1282  requestFromUrl(url);
1283  return;
1284  }
1285  }
1286  }
1287 
1288  m_status =
1290  m_statusText =
1292 
1293  if (m_state < HeadersReceived) {
1295  fillHeadersList ();
1297  if (cbv.isError()) printError(cbv);
1298  }
1300  readEncoding();
1301 
1302  if (xhrDump()) {
1303  qWarning().nospace() << "XMLHttpRequest: RESPONSE " << qPrintable(m_url.toString());
1304  if (!m_responseEntityBody.isEmpty()) {
1305  qWarning().nospace() << " "
1307  }
1308  }
1309 
1310 
1311  m_data.clear();
1312  destroyNetwork();
1313  if (m_state < Loading) {
1314  m_state = Loading;
1316  if (cbv.isError()) printError(cbv);
1317  }
1318  m_state = Done;
1320  if (cbv.isError()) printError(cbv);
1321 
1322  m_me = QScriptValue();
1323 }
The QVariant class acts like a union for the most common Qt data types.
Definition: qvariant.h:92
QString toString(FormattingOptions options=None) const
Returns the human-displayable string representation of the URL.
Definition: qurl.cpp:5896
QByteArray & append(char c)
Appends the character ch to this byte array.
QVariant attribute(QNetworkRequest::Attribute code) const
Returns the attribute associated with the code code.
bool isError() const
Returns true if this QScriptValue is an object of the Error class; otherwise returns false...
QLatin1String(DBUS_INTERFACE_DBUS))) Q_GLOBAL_STATIC_WITH_ARGS(QString
QDeclarativeGuard< QNetworkReply > m_network
The QUrl class provides a convenient interface for working with URLs.
Definition: qurl.h:61
QByteArray toByteArray() const
Returns the variant as a QByteArray if the variant has type() ByteArray or String (converted using QS...
Definition: qvariant.cpp:2383
#define XMLHTTPREQUEST_MAXIMUM_REDIRECT_RECURSION
int toInt(bool *ok=0) const
Returns the variant as an int if the variant has type() Int , Bool , ByteArray , Char ...
Definition: qvariant.cpp:2625
void printError(const QScriptValue &)
static QString fromUtf8(const char *, int size=-1)
Returns a QString initialized with the first size bytes of the UTF-8 string str.
Definition: qstring.cpp:4302
Q_CORE_EXPORT void qWarning(const char *,...)
QUrl toUrl() const
Returns the variant as a QUrl if the variant has type() Url ; otherwise returns an invalid QUrl...
Definition: qvariant.cpp:2528
QString scheme() const
Returns the scheme of the URL.
Definition: qurl.cpp:4550
QScriptValue dispatchCallback(QScriptValue *me)
QString toLower() const Q_REQUIRED_RESULT
Returns a lowercase copy of the string.
Definition: qstring.cpp:5389
QByteArray readAll()
Reads all available data from the device, and returns it as a QByteArray.
Definition: qiodevice.cpp:1025
bool isEmpty() const
Returns true if the byte array has size 0; otherwise returns false.
Definition: qbytearray.h:421
QUrl url() const
Returns the URL of the content downloaded or uploaded.
QUrl resolved(const QUrl &relative) const
Returns the result of the merge of this URL with relative.
Definition: qurl.cpp:5819
bool isValid() const
Returns true if the storage type of this variant is not QVariant::Invalid; otherwise returns false...
Definition: qvariant.h:485
#define qPrintable(string)
Definition: qglobal.h:1750
The QScriptValue class acts as a container for the Qt Script data types.
Definition: qscriptvalue.h:57
void clear()
Clears the contents of the byte array and makes it empty.

◆ header()

QString QDeclarativeXMLHttpRequest::header ( const QString name)

Definition at line 1078 of file qdeclarativexmlhttprequest.cpp.

Referenced by fillHeadersList(), headers(), qmlxmlhttprequest_getResponseHeader(), and readEncoding().

1079 {
1080  QByteArray utfname = name.toLower().toUtf8();
1081 
1082  foreach (const HeaderPair &header, m_headersList) {
1083  if (header.first == utfname)
1084  return QString::fromUtf8(header.second);
1085  }
1086  return QString();
1087 }
QByteArray toUtf8() const Q_REQUIRED_RESULT
Returns a UTF-8 representation of the string as a QByteArray.
Definition: qstring.cpp:4074
The QByteArray class provides an array of bytes.
Definition: qbytearray.h:135
The QString class provides a Unicode character string.
Definition: qstring.h:83
static QString fromUtf8(const char *, int size=-1)
Returns a QString initialized with the first size bytes of the UTF-8 string str.
Definition: qstring.cpp:4302
QPair< QByteArray, QByteArray > HeaderPair
QString header(const QString &name)
QString toLower() const Q_REQUIRED_RESULT
Returns a lowercase copy of the string.
Definition: qstring.cpp:5389

◆ headers()

QString QDeclarativeXMLHttpRequest::headers ( )

Definition at line 1089 of file qdeclarativexmlhttprequest.cpp.

Referenced by qmlxmlhttprequest_getAllResponseHeaders().

1090 {
1091  QString ret;
1092 
1093  foreach (const HeaderPair &header, m_headersList) {
1094  if (ret.length())
1095  ret.append(QLatin1String("\r\n"));
1096  ret = ret % QString::fromUtf8(header.first) % QLatin1String(": ")
1097  % QString::fromUtf8(header.second);
1098  }
1099  return ret;
1100 }
int length() const
Returns the number of characters in this string.
Definition: qstring.h:696
QLatin1String(DBUS_INTERFACE_DBUS))) Q_GLOBAL_STATIC_WITH_ARGS(QString
The QString class provides a Unicode character string.
Definition: qstring.h:83
static QString fromUtf8(const char *, int size=-1)
Returns a QString initialized with the first size bytes of the UTF-8 string str.
Definition: qstring.cpp:4302
The QLatin1String class provides a thin wrapper around an US-ASCII/Latin-1 encoded string literal...
Definition: qstring.h:654
QPair< QByteArray, QByteArray > HeaderPair
QString header(const QString &name)
QString & append(QChar c)
Definition: qstring.cpp:1777

◆ networkAccessManager()

QNetworkAccessManager* QDeclarativeXMLHttpRequest::networkAccessManager ( )
inlineprivate

Definition at line 1016 of file qdeclarativexmlhttprequest.cpp.

Referenced by qmlxmlhttprequest_new(), and requestFromUrl().

1016 { return m_nam; }

◆ open()

QScriptValue QDeclarativeXMLHttpRequest::open ( QScriptValue me,
const QString method,
const QUrl url 
)

◆ printError()

void QDeclarativeXMLHttpRequest::printError ( const QScriptValue sv)
private

Definition at line 1406 of file qdeclarativexmlhttprequest.cpp.

Referenced by downloadProgress(), error(), and finished().

1407 {
1411 }
void error(QNetworkReply::NetworkError)
static QDeclarativeEnginePrivate * get(QDeclarativeEngine *e)
QScriptEngine * engine() const
Returns the QScriptEngine that created this QScriptValue, or 0 if this QScriptValue is invalid or the...
The QDeclarativeError class encapsulates a QML error.
static void exceptionToError(QScriptEngine *, QDeclarativeError &)
void warning(const QDeclarativeError &)

◆ rawResponseBody()

const QByteArray & QDeclarativeXMLHttpRequest::rawResponseBody ( ) const

Definition at line 1395 of file qdeclarativexmlhttprequest.cpp.

Referenced by qmlxmlhttprequest_responseXML().

1396 {
1397  return m_responseEntityBody;
1398 }

◆ readEncoding()

void QDeclarativeXMLHttpRequest::readEncoding ( )
private

Definition at line 1326 of file qdeclarativexmlhttprequest.cpp.

Referenced by finished().

1327 {
1328  foreach (const HeaderPair &header, m_headersList) {
1329  if (header.first == "content-type") {
1330  int separatorIdx = header.second.indexOf(';');
1331  if (separatorIdx == -1) {
1332  m_mime == header.second;
1333  } else {
1334  m_mime = header.second.mid(0, separatorIdx);
1335  int charsetIdx = header.second.indexOf("charset=");
1336  if (charsetIdx != -1) {
1337  charsetIdx += 8;
1338  separatorIdx = header.second.indexOf(';', charsetIdx);
1339  m_charset = header.second.mid(charsetIdx, separatorIdx >= 0 ? separatorIdx : header.second.length());
1340  }
1341  }
1342  break;
1343  }
1344  }
1345 
1346  if (m_mime.isEmpty() || m_mime == "text/xml" || m_mime == "application/xml" || m_mime.endsWith("+xml"))
1347  m_gotXml = true;
1348 }
QByteArray mid(int index, int len=-1) const
Returns a byte array containing len bytes from this byte array, starting at position pos...
int indexOf(char c, int from=0) const
Returns the index position of the first occurrence of the character ch in the byte array...
QPair< QByteArray, QByteArray > HeaderPair
QString header(const QString &name)
bool isEmpty() const
Returns true if the byte array has size 0; otherwise returns false.
Definition: qbytearray.h:421
bool endsWith(const QByteArray &a) const
Returns true if this byte array ends with byte array ba; otherwise returns false. ...

◆ readyState()

quint32 QDeclarativeXMLHttpRequest::readyState ( ) const

◆ receivedXml()

bool QDeclarativeXMLHttpRequest::receivedXml ( ) const

Definition at line 1350 of file qdeclarativexmlhttprequest.cpp.

Referenced by qmlxmlhttprequest_responseXML().

1351 {
1352  return m_gotXml;
1353 }

◆ replyStatus()

int QDeclarativeXMLHttpRequest::replyStatus ( ) const

Definition at line 1045 of file qdeclarativexmlhttprequest.cpp.

Referenced by qmlxmlhttprequest_status().

1046 {
1047  return m_status;
1048 }

◆ replyStatusText()

QString QDeclarativeXMLHttpRequest::replyStatusText ( ) const

Definition at line 1050 of file qdeclarativexmlhttprequest.cpp.

Referenced by qmlxmlhttprequest_statusText().

1051 {
1052  return m_statusText;
1053 }

◆ requestFromUrl()

void QDeclarativeXMLHttpRequest::requestFromUrl ( const QUrl url)
private

Definition at line 1117 of file qdeclarativexmlhttprequest.cpp.

Referenced by finished(), and send().

1118 {
1119  QNetworkRequest request = m_request;
1120  request.setUrl(url);
1121  if(m_method == QLatin1String("POST") ||
1122  m_method == QLatin1String("PUT")) {
1124  if (var.isValid()) {
1125  QString str = var.toString();
1126  int charsetIdx = str.indexOf(QLatin1String("charset="));
1127  if (charsetIdx == -1) {
1128  // No charset - append
1129  if (!str.isEmpty()) str.append(QLatin1Char(';'));
1130  str.append(QLatin1String("charset=UTF-8"));
1131  } else {
1132  charsetIdx += 8;
1133  int n = 0;
1134  int semiColon = str.indexOf(QLatin1Char(';'), charsetIdx);
1135  if (semiColon == -1) {
1136  n = str.length() - charsetIdx;
1137  } else {
1138  n = semiColon - charsetIdx;
1139  }
1140 
1141  str.replace(charsetIdx, n, QLatin1String("UTF-8"));
1142  }
1144  } else {
1146  QLatin1String("text/plain;charset=UTF-8"));
1147  }
1148  }
1149 
1150  if (xhrDump()) {
1151  qWarning().nospace() << "XMLHttpRequest: " << qPrintable(m_method) << " " << qPrintable(url.toString());
1152  if (!m_data.isEmpty()) {
1153  qWarning().nospace() << " "
1155  }
1156  }
1157 
1158  if (m_method == QLatin1String("GET"))
1159  m_network = networkAccessManager()->get(request);
1160  else if (m_method == QLatin1String("HEAD"))
1161  m_network = networkAccessManager()->head(request);
1162  else if(m_method == QLatin1String("POST"))
1163  m_network = networkAccessManager()->post(request, m_data);
1164  else if(m_method == QLatin1String("PUT"))
1165  m_network = networkAccessManager()->put(request, m_data);
1166  else if (m_method == QLatin1String("DELETE"))
1168 
1170  this, SLOT(downloadProgress(qint64)));
1174  this, SLOT(finished()));
1175 }
The QVariant class acts like a union for the most common Qt data types.
Definition: qvariant.h:92
void setUrl(const QUrl &url)
Sets the URL this network request is referring to to be url.
QNetworkReply * head(const QNetworkRequest &request)
Posts a request to obtain the network headers for request and returns a new QNetworkReply object whic...
QString toString(FormattingOptions options=None) const
Returns the human-displayable string representation of the URL.
Definition: qurl.cpp:5896
QNetworkReply * put(const QNetworkRequest &request, QIODevice *data)
Uploads the contents of data to the destination request and returnes a new QNetworkReply object that ...
QString & replace(int i, int len, QChar after)
Definition: qstring.cpp:2005
int length() const
Returns the number of characters in this string.
Definition: qstring.h:696
#define SLOT(a)
Definition: qobjectdefs.h:226
QNetworkReply * deleteResource(const QNetworkRequest &request)
Sends a request to delete the resource identified by the URL of request.
QString toString() const
Returns the variant as a QString if the variant has type() String , Bool , ByteArray ...
Definition: qvariant.cpp:2270
NetworkError
Indicates all possible error conditions found during the processing of the request.
Definition: qnetworkreply.h:70
void error(QNetworkReply::NetworkError)
QLatin1String(DBUS_INTERFACE_DBUS))) Q_GLOBAL_STATIC_WITH_ARGS(QString
QDeclarativeGuard< QNetworkReply > m_network
The QString class provides a Unicode character string.
Definition: qstring.h:83
#define SIGNAL(a)
Definition: qobjectdefs.h:227
QVariant header(KnownHeaders header) const
Returns the value of the known network header header if it is present in this request.
static bool connect(const QObject *sender, const char *signal, const QObject *receiver, const char *member, Qt::ConnectionType=Qt::AutoConnection)
Creates a connection of the given type from the signal in the sender object to the method in the rece...
Definition: qobject.cpp:2580
bool isEmpty() const
Returns true if the string has no characters; otherwise returns false.
Definition: qstring.h:704
QNetworkAccessManager * networkAccessManager()
static QString fromUtf8(const char *, int size=-1)
Returns a QString initialized with the first size bytes of the UTF-8 string str.
Definition: qstring.cpp:4302
Q_CORE_EXPORT void qWarning(const char *,...)
int indexOf(QChar c, int from=0, Qt::CaseSensitivity cs=Qt::CaseSensitive) const
Definition: qstring.cpp:2838
__int64 qint64
Definition: qglobal.h:942
void setHeader(KnownHeaders header, const QVariant &value)
Sets the value of the known header header to be value, overriding any previously set headers...
QNetworkReply * get(const QNetworkRequest &request)
Posts a request to obtain the contents of the target request and returns a new QNetworkReply object o...
QString & append(QChar c)
Definition: qstring.cpp:1777
The QNetworkRequest class holds a request to be sent with QNetworkAccessManager.
QNetworkReply * post(const QNetworkRequest &request, QIODevice *data)
Sends an HTTP POST request to the destination specified by request and returns a new QNetworkReply ob...
bool isEmpty() const
Returns true if the byte array has size 0; otherwise returns false.
Definition: qbytearray.h:421
bool isValid() const
Returns true if the storage type of this variant is not QVariant::Invalid; otherwise returns false...
Definition: qvariant.h:485
#define qPrintable(string)
Definition: qglobal.h:1750
The QLatin1Char class provides an 8-bit ASCII/Latin-1 character.
Definition: qchar.h:55

◆ responseBody()

QString QDeclarativeXMLHttpRequest::responseBody ( )

Definition at line 1383 of file qdeclarativexmlhttprequest.cpp.

Referenced by qmlxmlhttprequest_responseText().

1384 {
1385 #ifndef QT_NO_TEXTCODEC
1386  if (!m_textCodec)
1388  if (m_textCodec)
1390 #endif
1391 
1393 }
static QString fromUtf8(const char *, int size=-1)
Returns a QString initialized with the first size bytes of the UTF-8 string str.
Definition: qstring.cpp:4302
QString toUnicode(const QByteArray &) const
Converts a from the encoding of this codec to Unicode, and returns the result in a QString...

◆ send()

QScriptValue QDeclarativeXMLHttpRequest::send ( QScriptValue me,
const QByteArray data 
)

Definition at line 1177 of file qdeclarativexmlhttprequest.cpp.

Referenced by qmlxmlhttprequest_send().

1178 {
1179  m_errorFlag = false;
1180  m_sendFlag = true;
1181  m_redirectCount = 0;
1182  m_data = data;
1183  m_me = *me;
1184 
1186 
1187  return QScriptValue();
1188 }
static const char * data(const QByteArray &arr)
The QScriptValue class acts as a container for the Qt Script data types.
Definition: qscriptvalue.h:57

◆ sendFlag()

bool QDeclarativeXMLHttpRequest::sendFlag ( ) const

Properties

◆ m_charset

QByteArray QDeclarativeXMLHttpRequest::m_charset
private

Definition at line 997 of file qdeclarativexmlhttprequest.cpp.

Referenced by findTextCodec(), and readEncoding().

◆ m_data

QByteArray QDeclarativeXMLHttpRequest::m_data
private

Definition at line 987 of file qdeclarativexmlhttprequest.cpp.

Referenced by error(), finished(), requestFromUrl(), and send().

◆ m_errorFlag

bool QDeclarativeXMLHttpRequest::m_errorFlag
private

Definition at line 982 of file qdeclarativexmlhttprequest.cpp.

Referenced by abort(), error(), errorFlag(), open(), and send().

◆ m_gotXml

bool QDeclarativeXMLHttpRequest::m_gotXml
private

Definition at line 995 of file qdeclarativexmlhttprequest.cpp.

Referenced by findTextCodec(), readEncoding(), and receivedXml().

◆ m_headersList

HeadersList QDeclarativeXMLHttpRequest::m_headersList
private

Definition at line 992 of file qdeclarativexmlhttprequest.cpp.

Referenced by fillHeadersList(), header(), headers(), and readEncoding().

◆ m_me

QScriptValue QDeclarativeXMLHttpRequest::m_me
private

Definition at line 1004 of file qdeclarativexmlhttprequest.cpp.

Referenced by downloadProgress(), error(), finished(), and send().

◆ m_method

QString QDeclarativeXMLHttpRequest::m_method
private

Definition at line 984 of file qdeclarativexmlhttprequest.cpp.

Referenced by finished(), open(), and requestFromUrl().

◆ m_mime

QByteArray QDeclarativeXMLHttpRequest::m_mime
private

Definition at line 996 of file qdeclarativexmlhttprequest.cpp.

Referenced by findTextCodec(), and readEncoding().

◆ m_nam

QNetworkAccessManager* QDeclarativeXMLHttpRequest::m_nam
private

Definition at line 1015 of file qdeclarativexmlhttprequest.cpp.

◆ m_network

QDeclarativeGuard<QNetworkReply> QDeclarativeXMLHttpRequest::m_network
private

◆ m_redirectCount

int QDeclarativeXMLHttpRequest::m_redirectCount
private

Definition at line 988 of file qdeclarativexmlhttprequest.cpp.

Referenced by finished(), and send().

◆ m_request

QNetworkRequest QDeclarativeXMLHttpRequest::m_request
private

Definition at line 1011 of file qdeclarativexmlhttprequest.cpp.

Referenced by abort(), addHeader(), error(), and requestFromUrl().

◆ m_responseEntityBody

QByteArray QDeclarativeXMLHttpRequest::m_responseEntityBody
private

◆ m_sendFlag

bool QDeclarativeXMLHttpRequest::m_sendFlag
private

Definition at line 983 of file qdeclarativexmlhttprequest.cpp.

Referenced by abort(), open(), send(), and sendFlag().

◆ m_state

State QDeclarativeXMLHttpRequest::m_state
private

◆ m_status

int QDeclarativeXMLHttpRequest::m_status
private

Definition at line 1009 of file qdeclarativexmlhttprequest.cpp.

Referenced by downloadProgress(), error(), finished(), and replyStatus().

◆ m_statusText

QString QDeclarativeXMLHttpRequest::m_statusText
private

◆ m_textCodec

QTextCodec* QDeclarativeXMLHttpRequest::m_textCodec
private

Definition at line 998 of file qdeclarativexmlhttprequest.cpp.

Referenced by responseBody().

◆ m_url

QUrl QDeclarativeXMLHttpRequest::m_url
private

Definition at line 985 of file qdeclarativexmlhttprequest.cpp.

Referenced by finished(), open(), and send().


The documentation for this class was generated from the following file: