本文整理汇总了C++中QTcpSocket::pos方法的典型用法代码示例。如果您正苦于以下问题:C++ QTcpSocket::pos方法的具体用法?C++ QTcpSocket::pos怎么用?C++ QTcpSocket::pos使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QTcpSocket
的用法示例。
在下文中一共展示了QTcpSocket::pos方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: constructing_QTcpSocket
//----------------------------------------------------------------------------------
void tst_QIODevice::constructing_QTcpSocket()
{
#if defined(Q_OS_WINCE) && defined(WINCE_EMULATOR_TEST)
QSKIP("Networking tests in a WinCE emulator are unstable", SkipAll);
#endif
QTcpSocket socket;
QIODevice *device = &socket;
QVERIFY(!device->isOpen());
socket.connectToHost(QtNetworkSettings::serverName(), 143);
QVERIFY(socket.waitForConnected(5000));
QVERIFY(device->isOpen());
while (!device->canReadLine())
QVERIFY(device->waitForReadyRead(5000));
char buf[1024];
memset(buf, 0, sizeof(buf));
qlonglong lineLength = device->readLine(buf, sizeof(buf));
QVERIFY(lineLength > 0);
QCOMPARE(socket.pos(), qlonglong(0));
socket.close();
socket.connectToHost(QtNetworkSettings::serverName(), 143);
QVERIFY(socket.waitForConnected(5000));
QVERIFY(device->isOpen());
while (!device->canReadLine())
QVERIFY(device->waitForReadyRead(5000));
char buf2[1024];
memset(buf2, 0, sizeof(buf2));
QCOMPARE(socket.readLine(buf2, sizeof(buf2)), lineLength);
char *c1 = buf;
char *c2 = buf2;
while (*c1 && *c2) {
QCOMPARE(*c1, *c2);
++c1;
++c2;
}
QCOMPARE(*c1, *c2);
}