diff options
Diffstat (limited to 'examples/network/doc/src/blockingfortuneclient.qdoc')
-rw-r--r-- | examples/network/doc/src/blockingfortuneclient.qdoc | 43 |
1 files changed, 13 insertions, 30 deletions
diff --git a/examples/network/doc/src/blockingfortuneclient.qdoc b/examples/network/doc/src/blockingfortuneclient.qdoc index fbbfd466a5..6719a4e0b9 100644 --- a/examples/network/doc/src/blockingfortuneclient.qdoc +++ b/examples/network/doc/src/blockingfortuneclient.qdoc @@ -1,7 +1,7 @@ /**************************************************************************** ** -** Copyright (C) 2015 The Qt Company Ltd. -** Contact: http://www.qt.io/licensing/ +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ ** ** This file is part of the documentation of the Qt Toolkit. ** @@ -11,8 +11,8 @@ ** accordance with the commercial license agreement provided with the ** Software or, alternatively, in accordance with the terms contained in ** a written agreement between you and The Qt Company. For licensing terms -** and conditions see http://www.qt.io/terms-conditions. For further -** information use the contact form at http://www.qt.io/contact-us. +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. ** ** GNU Free Documentation License Usage ** Alternatively, this file may be used under the terms of the GNU Free @@ -20,7 +20,7 @@ ** Foundation and appearing in the file included in the packaging of ** this file. Please review the following information to ensure ** the GNU Free Documentation License version 1.3 requirements -** will be met: http://www.gnu.org/copyleft/fdl.html. +** will be met: https://www.gnu.org/licenses/fdl-1.3.html. ** $QT_END_LICENSE$ ** ****************************************************************************/ @@ -125,39 +125,22 @@ other \c waitFor...() functions, is part of QTcpSocket's \e{blocking API}. - After this statement, we have a connected socket to work with. Now it's - time to see what the fortune server has sent us. - - \snippet blockingfortuneclient/fortunethread.cpp 9 - \snippet blockingfortuneclient/fortunethread.cpp 10 - - This step is to read the size of the packet. Although we are only reading - two bytes here, and the \c while loop may seem to overdo it, we present this - code to demonstrate a good pattern for waiting for data using - QTcpSocket::waitForReadyRead(). It goes like this: For as long as we still - need more data, we call waitForReadyRead(). If it returns false, - we abort the operation. After this statement, we know that we have received - enough data. + After this statement, we have a connected socket to work with. \snippet blockingfortuneclient/fortunethread.cpp 11 Now we can create a QDataStream object, passing the socket to QDataStream's constructor, and as in the other client examples we set - the stream protocol version to QDataStream::Qt_4_0, and read the size - of the packet. + the stream protocol version to QDataStream::Qt_4_0. \snippet blockingfortuneclient/fortunethread.cpp 12 - \snippet blockingfortuneclient/fortunethread.cpp 13 - - Again, we'll use a loop that waits for more data by calling - QTcpSocket::waitForReadyRead(). In this loop, we're waiting until - QTcpSocket::bytesAvailable() returns the full packet size. - - \snippet blockingfortuneclient/fortunethread.cpp 14 - Now that we have all the data that we need, we can use QDataStream to - read the fortune string from the packet. The resulting fortune is - delivered by emitting newFortune(). + We proceed by initiating a loop that waits for the fortune string data by + calling QTcpSocket::waitForReadyRead(). If it returns false, we abort the + operation. After this statement, we start a stream read transaction. We + exit the loop when QDataStream::commitTransaction() returns true, which + means successful fortune string loading. The resulting fortune is + delivered by emitting newFortune(): \snippet blockingfortuneclient/fortunethread.cpp 15 |