bool QIODeviceProto::canReadLine() const { QIODevice *item = qscriptvalue_cast<QIODevice*>(thisObject()); if (item) return item->canReadLine(); return false; }
//---------------------------------------------------------------------------------- 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); }
void SocketApi::slotReadSocket() { QIODevice* socket = qobject_cast<QIODevice*>(sender()); Q_ASSERT(socket); while(socket->canReadLine()) { QString line = QString::fromUtf8(socket->readLine()); line.chop(1); // remove the '\n' QString command = line.split(":").value(0); QString function = QString(QLatin1String("command_")).append(command); QString functionWithArguments = function + QLatin1String("(QString,QIODevice*)"); int indexOfMethod = this->metaObject()->indexOfMethod(functionWithArguments.toAscii()); QString argument = line.remove(0, command.length()+1); if(indexOfMethod != -1) { QMetaObject::invokeMethod(this, function.toAscii(), Q_ARG(QString, argument), Q_ARG(QIODevice*, socket)); } else {
bool FlushedProcess::canReadLine() const { QIODevice * dev = readingIODevice(); return (dev == NULL)?false:dev->canReadLine(); }