我是QT和C + +新手,我想创建一个QTcpserver使用QThreadpools,因此它可以处理多个客户端。多个客户端能够无任何问题地连接。但是我试图从Android手机发送一个图像,脚本“IMGPNG”,指示图像数据的结束。现在,readyRead信号发出时的问题我正在读取所有可用数据,然后稍后执行一些字符串操作并重建图像。我不知道如何接收每个客户的完整图像,然后相应地处理它。Qt使用线程池,无法一次接收readyRead()
void VireClients::readyRead()//read ready
{
int nsize = socket->bytesAvailable();//trying to check the available bytes
qDebug()<< "Bytes Available" << nsize;
while(socket->bytesAvailable() < nsize){
QByteArray data = socket->readAll();//how to receive all the data and then process it
}
/*!These lines call the threadpool instance and reimplement run*/
imageAnalysis = new VireImageAnalysis(); //creating a new instance of the QRunnable
imageAnalysis->setAutoDelete(true);
connect(imageAnalysis,SIGNAL(ImageAnalysisResult(int)),this,SLOT(TaskResult(int)),Qt::QueuedConnection);
QThreadPool::globalInstance()->start(imageAnalysis);
}
现在我不知道如何完全获取数据或将接收到的数据保存为图像格式。我想知道如何完全接收图像数据。请帮忙。
我会建议使用boost Asio代替网络,因为Qt实现中有可能导致数据丢失的错误。如果你想坚持使用Qt来处理这些事情,可以看看财富服务器/客户端的例子。 – Pete
不要检查'bytesAvailable'。请阅读尽可能多的内容。如果你没有得到全部,请阅读更多内容。 –