2

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?

cbuchart
  • 10,847
  • 9
  • 53
  • 93
Umriyaev
  • 1,150
  • 11
  • 17
  • Can try to print out something in release mode, so you can see what happened. – Hải Phạm Lê Jun 23 '17 at 00:58
  • @Hải Phạm Lê I'm already printing size of incoming byte array and it's save in both debug and release modes, and also in both dev PC and other PCs. – Umriyaev Jun 23 '17 at 01:15
  • 1
    Must be this or similar issue: https://stackoverflow.com/questions/6724606/include-the-jpeg-plugin-in-my-application – Alexander V Jun 23 '17 at 03:16

1 Answers1

1

If it is working in your development system, then probably you're still missing some DLL. Unfortunately, Qt's will complain only for mandatory DLLs, but there are other ones, the plugins, that are optional, and certain functionalities will be possible only if they are present (such as reading some image formats) without showing any DLL missing error.

Copy the <QTDIR>\plugins\imageformats folder (where <QTDIR> is the installation path of your Qt version, such as C:\Qt\qt_5_6_1\msvc2010 in my case) to the same directory where your executable is. Be aware that debug and release binaries are mixed in the same folder, so just copy the ones corresponding to your build configuration.

Your project dir should look something like:

project\
        project.exe
        Qt5Core.dll
        Qt5Gui.dll
        ...
        imageformats\
                     qgif.dll
                     qico.dll
                     qjpeg.dll
                     ...

The Qt VS Add-on automatically adds some directories to the path, that's why it doesn't fail when run from the IDE.

Note: if you want to use SVG images you'll have to also copy iconengines\qsvgicon.dll and Qt5Svg.dll.

cbuchart
  • 10,847
  • 9
  • 53
  • 93
  • Thank you for your answer. @AlexanderVX ' s comment was helpful too. I solved my problem after his comment. And your answer is similar to the post he pointed, so I accepted your answer as the answer to my post. – Umriyaev Jun 28 '17 at 07:15