This change moves the snippets and imagesto the modularized directories.
Change-Id: If14912692a7f72d7de345eaf88d9ec9752310fca
Reviewed-by: Marius Storm-Olsen <marius.storm-olsen@nokia.com>
e.g. if you want to connect and login to a FTP server. This is
simply achieved:
- \snippet doc/src/snippets/code/src_network_access_qftp.cpp 0
+ \snippet code/src_network_access_qftp.cpp 0
In this case two FTP commands have been scheduled. When the last
scheduled command has finished, a done() signal is emitted with
Example: If you want to download the INSTALL file from the Qt
FTP server, you would write this:
- \snippet doc/src/snippets/code/src_network_access_qftp.cpp 1
+ \snippet code/src_network_access_qftp.cpp 1
For this example the following sequence of signals is emitted
(with small variations, depending on network traffic, etc.):
- \snippet doc/src/snippets/code/src_network_access_qftp.cpp 2
+ \snippet code/src_network_access_qftp.cpp 2
The dataTransferProgress() signal in the above example is useful
if you want to show a \link QProgressBar progress bar \endlink to
If the login fails for the above example, the signals would look
like this:
- \snippet doc/src/snippets/code/src_network_access_qftp.cpp 3
+ \snippet code/src_network_access_qftp.cpp 3
You can then get details about the error with the error() and
errorString() functions.
and a data block, which are separated by each other by two
consecutive new lines. An example for one part would be:
- \snippet doc/src/snippets/code/src_network_access_qhttppart.cpp 0
+ \snippet code/src_network_access_qhttppart.cpp 0
For setting headers, use setHeader() and setRawHeader(), which behave
exactly like QNetworkRequest::setHeader() and QNetworkRequest::setRawHeader().
To construct a QHttpPart with a small body, consider the following snippet
(this produces the data shown in the example above):
- \snippet doc/src/snippets/code/src_network_access_qhttppart.cpp 1
+ \snippet code/src_network_access_qhttppart.cpp 1
To construct a QHttpPart reading from a device (e.g. a file), the following
can be applied:
- \snippet doc/src/snippets/code/src_network_access_qhttppart.cpp 2
+ \snippet code/src_network_access_qhttppart.cpp 2
Be aware that QHttpPart does not take ownership of the device when set, so
it is the developer's responsibility to destroy it when it is not needed anymore.
As an example, consider the following code snippet, which constructs a multipart
message containing a text part followed by an image part:
- \snippet doc/src/snippets/code/src_network_access_qhttpmultipart.cpp 0
+ \snippet code/src_network_access_qhttpmultipart.cpp 0
\sa QHttpPart, QNetworkAccessManager::post()
*/
returned in response to the corresponding request.
A simple download off the network could be accomplished with:
- \snippet doc/src/snippets/code/src_network_access_qnetworkaccessmanager.cpp 0
+ \snippet code/src_network_access_qnetworkaccessmanager.cpp 0
QNetworkAccessManager has an asynchronous API.
When the \tt replyFinished slot above is called, the parameter it
A more involved example, assuming the manager is already existent,
can be:
- \snippet doc/src/snippets/code/src_network_access_qnetworkaccessmanager.cpp 1
+ \snippet code/src_network_access_qnetworkaccessmanager.cpp 1
\section1 Network and Roaming support
By default the value of this property reflects the physical state of the device. Applications
may override it to disable all network requests via this network access manager by calling
- \snippet doc/src/snippets/code/src_network_access_qnetworkaccessmanager.cpp 4
+ \snippet code/src_network_access_qnetworkaccessmanager.cpp 4
Network requests can be reenabled again by calling
- \snippet doc/src/snippets/code/src_network_access_qnetworkaccessmanager.cpp 5
+ \snippet code/src_network_access_qnetworkaccessmanager.cpp 5
\note Calling setNetworkAccessible() does not change the network state.
*/
To restore the default network configuration set the network configuration to the value
returned from QNetworkConfigurationManager::defaultConfiguration().
- \snippet doc/src/snippets/code/src_network_access_qnetworkaccessmanager.cpp 2
+ \snippet code/src_network_access_qnetworkaccessmanager.cpp 2
If an invalid network configuration is set, a network session will not be created. In this
case network requests will be processed regardless, but may fail. For example:
- \snippet doc/src/snippets/code/src_network_access_qnetworkaccessmanager.cpp 3
+ \snippet code/src_network_access_qnetworkaccessmanager.cpp 3
\sa configuration(), QNetworkSession
*/
A network disk cache can be enabled by:
- \snippet doc/src/snippets/code/src_network_access_qnetworkdiskcache.cpp 0
+ \snippet code/src_network_access_qnetworkdiskcache.cpp 0
When sending requests, to control the preference of when to use the cache
and when to use the network, consider the following:
- \snippet doc/src/snippets/code/src_network_access_qnetworkdiskcache.cpp 1
+ \snippet code/src_network_access_qnetworkdiskcache.cpp 1
To check whether the response came from the cache or from the network, the
following can be applied:
- \snippet doc/src/snippets/code/src_network_access_qnetworkdiskcache.cpp 2
+ \snippet code/src_network_access_qnetworkdiskcache.cpp 2
*/
/*!
If, for instance, you want to issue a request to a server that uses
a self-signed certificate, consider the following snippet:
- \snippet doc/src/snippets/code/src_network_access_qnetworkreply.cpp 0
+ \snippet code/src_network_access_qnetworkreply.cpp 0
Multiple calls to this function will replace the list of errors that
were passed in previous calls.
the corresponding "cooked" header will be set as well.
For example:
- \snippet doc/src/snippets/code/src_network_access_qnetworkrequest.cpp 0
+ \snippet code/src_network_access_qnetworkrequest.cpp 0
will also set the known header LastModifiedHeader to be the
QDateTime object of the parsed date.
This is equivalent to the following code snippet:
- \snippet doc/src/snippets/code/src_network_bearer_qnetworkconfigmanager.cpp 0
+ \snippet code/src_network_bearer_qnetworkconfigmanager.cpp 0
\sa onlineStateChanged()
*/
For example, you can determine which servers an XMPP chat client should
connect to for a given domain with:
- \snippet doc/src/snippets/code/src_network_kernel_qdnslookup.cpp 0
+ \snippet code/src_network_kernel_qdnslookup.cpp 0
Once the request finishes you can handle the results with:
- \snippet doc/src/snippets/code/src_network_kernel_qdnslookup.cpp 1
+ \snippet code/src_network_kernel_qdnslookup.cpp 1
\note If you simply want to find the IP address(es) associated with a host
name, or the host name associated with an IP address you should use
Returns the IPv6 address as a Q_IPV6ADDR structure. The structure
consists of 16 unsigned characters.
- \snippet doc/src/snippets/code/src_network_kernel_qhostaddress.cpp 0
+ \snippet code/src_network_kernel_qhostaddress.cpp 0
This value is valid if the protocol() is
\l{QAbstractSocket::}{IPv6Protocol}.
Example:
- \snippet doc/src/snippets/code/src_network_kernel_qhostinfo.cpp 0
+ \snippet code/src_network_kernel_qhostinfo.cpp 0
The slot is invoked when the results are ready. The results are
If you want a blocking lookup, use the QHostInfo::fromName() function:
- \snippet doc/src/snippets/code/src_network_kernel_qhostinfo.cpp 1
+ \snippet code/src_network_kernel_qhostinfo.cpp 1
QHostInfo supports Internationalized Domain Names (IDNs) through the
IDNA and Punycode standards.
The lookup is performed by a single function call, for example:
- \snippet doc/src/snippets/code/src_network_kernel_qhostinfo.cpp 2
+ \snippet code/src_network_kernel_qhostinfo.cpp 2
The implementation of the slot prints basic information about the
addresses returned by the lookup, or reports an error if it failed:
- \snippet doc/src/snippets/code/src_network_kernel_qhostinfo.cpp 3
+ \snippet code/src_network_kernel_qhostinfo.cpp 3
If you pass a literal IP address to \a name instead of a host name,
QHostInfo will search for the domain name for the IP (i.e., QHostInfo will
contain both the resolved domain name and IP addresses for the host
name. Example:
- \snippet doc/src/snippets/code/src_network_kernel_qhostinfo.cpp 4
+ \snippet code/src_network_kernel_qhostinfo.cpp 4
\note There is no guarantee on the order the signals will be emitted
if you start multiple requests with lookupHost().
Example:
- \snippet doc/src/snippets/code/src_network_kernel_qhostinfo.cpp 5
+ \snippet code/src_network_kernel_qhostinfo.cpp 5
\sa hostName(), error()
*/
network-enabled applications that you have written should
automatically support network proxy using the following code.
- \snippet doc/src/snippets/code/src_network_kernel_qnetworkproxy.cpp 0
+ \snippet code/src_network_kernel_qnetworkproxy.cpp 0
An alternative to setting an application wide proxy is to specify
the proxy for individual sockets using QAbstractSocket::setProxy()
and QTcpServer::setProxy(). In this way, it is possible to disable
the use of a proxy for specific sockets using the following code:
- \snippet doc/src/snippets/code/src_network_kernel_qnetworkproxy.cpp 1
+ \snippet code/src_network_kernel_qnetworkproxy.cpp 1
Network proxy is not used if the address used in \l
{QAbstractSocket::connectToHost()}{connectToHost()}, \l
the corresponding "cooked" header will be set as well.
For example:
- \snippet doc/src/snippets/code/src_network_access_qnetworkrequest.cpp 0
+ \snippet code/src_network_access_qnetworkrequest.cpp 0
will also set the known header LastModifiedHeader to be the
QDateTime object of the parsed date.
We show an example:
- \snippet doc/src/snippets/network/tcpwait.cpp 0
+ \snippet network/tcpwait.cpp 0
If \l{QIODevice::}{waitForReadyRead()} returns false, the
connection has been closed or an error has occurred.
The following example waits up to one second for a connection
to be established:
- \snippet doc/src/snippets/code/src_network_socket_qabstractsocket.cpp 0
+ \snippet code/src_network_socket_qabstractsocket.cpp 0
If msecs is -1, this function will not time out.
The following example waits up to one second for a connection
to be closed:
- \snippet doc/src/snippets/code/src_network_socket_qabstractsocket.cpp 1
+ \snippet code/src_network_socket_qabstractsocket.cpp 1
If msecs is -1, this function will not time out.
This function is most commonly used when reading data from the
socket in a loop. For example:
- \snippet doc/src/snippets/code/src_network_socket_qabstractsocket.cpp 2
+ \snippet code/src_network_socket_qabstractsocket.cpp 2
\sa bytesAvailable(), readyRead()
*/
To disable the use of a proxy for this socket, use the
QNetworkProxy::NoProxy proxy type:
- \snippet doc/src/snippets/code/src_network_socket_qabstractsocket.cpp 3
+ \snippet code/src_network_socket_qabstractsocket.cpp 3
The default value for the proxy is QNetworkProxy::DefaultProxy,
which means the socket will use the application settings: if a
The following example waits up to one second for a connection
to be established:
- \snippet doc/src/snippets/code/src_network_socket_qlocalsocket_unix.cpp 0
+ \snippet code/src_network_socket_qlocalsocket_unix.cpp 0
If \a msecs is -1, this function will not time out.
The following example waits up to one second for a connection
to be closed:
- \snippet doc/src/snippets/code/src_network_socket_qlocalsocket_unix.cpp 1
+ \snippet code/src_network_socket_qlocalsocket_unix.cpp 1
If \a msecs is -1, this function will not time out.
waitForWrite().
Example:
- \snippet doc/src/snippets/code/src_network_socket_qnativesocketengine.cpp 0
+ \snippet code/src_network_socket_qnativesocketengine.cpp 0
Otherwise, error() should be called to determine the cause of the
error.
the blocking function waitForRead().
Example:
- \snippet doc/src/snippets/code/src_network_socket_qnativesocketengine.cpp 1
+ \snippet code/src_network_socket_qnativesocketengine.cpp 1
\sa bind(), accept()
*/
To disable the use of a proxy for this socket, use the
QNetworkProxy::NoProxy proxy type:
- \snippet doc/src/snippets/code/src_network_socket_qtcpserver.cpp 0
+ \snippet code/src_network_socket_qtcpserver.cpp 0
\sa proxy(), QNetworkProxy
*/
Example:
- \snippet doc/src/snippets/code/src_network_socket_qudpsocket.cpp 0
+ \snippet code/src_network_socket_qudpsocket.cpp 0
QUdpSocket also supports UDP multicast. Use joinMulticastGroup() and
leaveMulticastGroup() to control group membership, and
Example:
- \snippet doc/src/snippets/code/src_network_ssl_qsslcertificate.cpp 0
+ \snippet code/src_network_ssl_qsslcertificate.cpp 0
\sa fromData()
*/
achieve that. The following example illustrates how to change the
protocol to TLSv1_0 in a QSslSocket object:
- \snippet doc/src/snippets/code/src_network_ssl_qsslconfiguration.cpp 0
+ \snippet code/src_network_ssl_qsslconfiguration.cpp 0
\sa QSsl::SslProtocol, QSslCertificate, QSslCipher, QSslKey
QSslSocket, QNetworkAccessManager,
This method starts an immediate SSL handshake once the connection
has been established.
- \snippet doc/src/snippets/code/src_network_ssl_qsslsocket.cpp 0
+ \snippet code/src_network_ssl_qsslsocket.cpp 0
As with a plain QTcpSocket, QSslSocket enters the HostLookupState,
ConnectingState, and finally the ConnectedState, if the connection
the existing one passed in. It then initiates the SSL handshake
by calling startServerEncryption().
- \snippet doc/src/snippets/code/src_network_ssl_qsslsocket.cpp 1
+ \snippet code/src_network_ssl_qsslsocket.cpp 1
If an error occurs, QSslSocket emits the sslErrors() signal. In this
case, if no action is taken to ignore the error(s), the connection
waitForEncrypted(), which will block the calling thread until an
encrypted connection has been established.
- \snippet doc/src/snippets/code/src_network_ssl_qsslsocket.cpp 2
+ \snippet code/src_network_ssl_qsslsocket.cpp 2
QSslSocket provides an extensive, easy-to-use API for handling
cryptographic ciphers, private keys, and local, peer, and
If the SSL handshake is successful, QSslSocket emits encrypted().
- \snippet doc/src/snippets/code/src_network_ssl_qsslsocket.cpp 3
+ \snippet code/src_network_ssl_qsslsocket.cpp 3
\b{Note:} The example above shows that text can be written to
the socket immediately after requesting the encrypted connection,
is a colon-separated list of cipher suite names. The ciphers are listed in
order of preference, starting with the most preferred cipher. For example:
- \snippet doc/src/snippets/code/src_network_ssl_qsslsocket.cpp 4
+ \snippet code/src_network_ssl_qsslsocket.cpp 4
Each cipher name in \a ciphers must be the name of a cipher in the
list returned by supportedCiphers(). Restricting the cipher suite
The following example waits up to one second for the socket to be
encrypted:
- \snippet doc/src/snippets/code/src_network_ssl_qsslsocket.cpp 5
+ \snippet code/src_network_ssl_qsslsocket.cpp 5
If msecs is -1, this function will not time out.
If, for instance, you want to connect to a server that uses
a self-signed certificate, consider the following snippet:
- \snippet doc/src/snippets/code/src_network_ssl_qsslsocket.cpp 6
+ \snippet code/src_network_ssl_qsslsocket.cpp 6
Multiple calls to this function will replace the list of errors that
were passed in previous calls.