Не получается отправлять и читать большие файлы. Что я делаю не так:
Вот отправка :
void ExchangeRateClient::beginRequest()
{
m_socket = new QTcpSocket();
connect(m_socket, SIGNAL(connected()), this, SLOT(connectedHandle()));
m_socket->connectToHost(m_serverAddress, m_serverPort);
}
void ExchangeRateClient::connectedHandle()
{
if(!m_socket->isValid())
{
qCritical() << "Could not connect to server. Action canceled.";
return;
}
QByteArray xmlData = m_requestInfo->xml().toUtf8();
m_xml = new QDataStream(xmlData);
connect(m_socket, SIGNAL(bytesWritten(qint64)), this, SLOT(sendNextXmlPiece(qint64)));
QByteArray block;
QDataStream out(&block, QIODevice::WriteOnly);
out.setVersion(QDataStream::Qt_5_3);
out << quint64(xmlData.size());
m_socket->write(block);
connect(m_socket, SIGNAL(readyRead()), this, SLOT(responseHandle()));
connect(m_socket, SIGNAL(disconnected()), this, SLOT(disconnectedHandle()));
connect(m_socket, SIGNAL(error(QAbstractSocket::SocketError)), this, SLOT(errorHandle(QAbstractSocket::SocketError)));
}
void ExchangeRateClient::sendNextXmlPiece(qint64 bytes)
{
if(m_socket->bytesToWrite() > XML_CHUNK_SIZE
|| m_xml->atEnd()) {
delete m_xml;
m_xml = NULL;
return;
}
long int lBytes = 0;
char buffer[XML_CHUNK_SIZE];
buffer[XML_CHUNK_SIZE - 1] = '\0';
int l = m_xml->readRawData(buffer, sizeof(char)* (XML_CHUNK_SIZE - 1));
QByteArray ba(buffer, sizeof(char)*l);
lBytes = m_socket->write(ba, sizeof(char)*l);
qDebug() << QString(buffer);
qDebug() << lBytes;
m_socket->waitForBytesWritten();
}
Почему-то сигнал bytesWriten срабатыват только 1 раз