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
tcpwait.cpp
Go to the documentation of this file.
1// Copyright (C) 2016 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
3
4#include <QTcpSocket>
5
7{
9 socket.connectToHost("localhost", 1025);
10
12 int numRead = 0, numReadTotal = 0;
13 char buffer[50];
14
15 forever {
16 numRead = socket.read(buffer, 50);
17
18 // do whatever with array
19
20 numReadTotal += numRead;
21 if (numRead == 0 && !socket.waitForReadyRead())
22 break;
23 }
25 return numReadTotal;
26}
bool waitForReadyRead(int msecs=30000) override
This function blocks until new data is available for reading and the \l{QIODevice::}{readyRead()} sig...
virtual void connectToHost(const QString &hostName, quint16 port, OpenMode mode=ReadWrite, NetworkLayerProtocol protocol=AnyIPProtocol)
Attempts to make a connection to hostName on the given port.
qint64 read(char *data, qint64 maxlen)
Reads at most maxSize bytes from the device into data, and returns the number of bytes read.
The QTcpSocket class provides a TCP socket.
Definition qtcpsocket.h:18
#define forever
Definition qforeach.h:78
GLenum GLuint buffer
QTcpSocket * socket
[1]
int test_tcpwait()
Definition tcpwait.cpp:6