In my app I receive images in JPEG
format from Android device over QTcpSocket
as a byte array.
When I run this app on my dev PC it works like a charm (both in debug and release modes). However, I'm not able to load QImage
from byte array on another PC where Qt is not installed.
I included all the *.dll files in Qt for my platform (Windows x64, msvc_2015_64) and also installed Visual Studio C++ Redistributable 2015. My app starts fine (doesn't give any errors that some *.dll files are missing). But QImage
is empty all the time.
First I thought that byte array wasn't being received at all, so I checked its size and found that it's being received correctly.
I'm using this code to load QImage
from uchar
bytes:
void handleImageBytes(uchar *bytes, qint64 length)
{
QImage image;
image.loadFromData(bytes, length, "JPEG");
emit frameReady(image);
}
And I receive those bytes from QTcpSocket
:
void handleReadyRead()
{
if(this->incomingFrameLength==0){
QString data = this->client->readAll();
this->incomingFrameLength = data.toInt();
this->client->write("ok");
qDebug()<<QString("Received frame length: %1").arg(this->incomingFrameLength);
return;
}
if(this->incomingFrameLength!=0 && this->client->bytesAvailable()<this->incomingFrameLength)
return;
uchar* data = (uchar*)malloc(this->incomingFrameLength+256);
qint64 len = this->client->read((char*)data, this->incomingFrameLength+256);
qDebug() << QString("Received %1 bytes").arg(len);
handleImageBytes(data, len);
this->incomingFrameLength=0;
this->client->write("received");
qDebug()<<QString("Received frame of length %1").arg(len);
free(data);
}
As you see, first I receive the size of the image as a length of the byte array.
Then I wait for all the required bytes are received and ready in the QTcpSocket
's buffer. Then I create pointer to the byte array with sufficient size, load incoming bytes to that array and call handleImageBytes
method from above.
This all works fine on my dev PC (Windows 7 x64, Qt 5.7, msvc_2015_64). However, loading images from byte array doesn't work when I move my release code with all the required *.dll files to other PC where Qt isn't installed.
How to solve this problem?