15

TcpSocket对象发送数据后,没有触发bytesWritten信号

connect(m_pClient, SIGNAL(bytesWritten(qint64)), this, SLOT(updateProgress(qint64)));//这里连接信号和槽

void SendFileDialog::readMessage()
{
QDataStream in(m_pClient);
in.setVersion(QDataStream::Qt_5_7);

quint8 isRecive;
in >> isRecive;
if (isRecive == 1)
{
    QByteArray block;
    ...............................
    m_bytesToWrite = m_allBytes - m_pClient->write(block);
    //这里发送数据后,正常地进入了updateProgress这个槽
}
else
{
...............................................
}

}
void SendFileDialog::updateProgress(qint64 byteNum)
{
.............................................
qApp->processEvents();
m_bytesWritten += byteNum;
QByteArray block;
QDataStream out(&block, QIODevice::WriteOnly);
out.setVersion(QDataStream::Qt_5_7);
if (m_bytesToWrite > 0)
{
out << m_file->read(qMin(m_bytesToWrite, payloadSize));
m_bytesToWrite -= (int)m_pClient->write(block);
//但这里发送数据后,没有再进入updateProgress这个槽
block.resize(0);
}
else
{
m_file->close();
}
.........................................
}
这段代码是从书上搬下来的,以前都没问题,这次不知道怎么回事,求大佬救命啊!
还有,环境是vs2015+Qt5.7.1(但应该与这个无关吧)

查看全部
qq814437727
qq814437727
2017/07/05 08:29
  • qt
  • 点赞
  • 收藏
  • 回答
    私信
满意答案
查看全部

1个回复