最近我编写了用 Qt 进行文件传输的程序。认为它现在有效,我仍然对发生了什么感到好奇。请帮我找出原因。非常感谢。
为什么 head 的大小大于 sizeof(qin32)、sizeof(qint32) 和文件名长度的总和?(我猜是函数的原因 - setVersion())
QFileInfo info(file_to_send.fileName());
QByteArray head;
QDataStream out(&head, QIODevice::WriteOnly);
out.setVersion(QDataStream::Qt_5_0);
out << qint32(file_to_send.size() + info.fileName().length() + sizeof(qint32)*2)
<< qint32(info.fileName().length())
<< info.fileName();
tcpClient.write(head);