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(但应该与这个无关吧)