Search code examples
qtdata-conversionqstringqpixmapqtcpsocket

Convert Binary QString to QPixmap


I'm receiving a binary thru FTP and storing it as a QString. The original image was BMP but to pass through FTP I converted it to QPixmap. I'm able to successfully receive this binary but I can't convert back to a QPixmap or some sort of format to display that image.

Does anyone have any suggestion?


Solution

  • 1) Convert QString to QByteArray data with QString::toLatin1(), QString::toLocal8Bit(). Think work only one of methods

    2) Read QByteArray with

    bool QPixmap::loadFromData(const QByteArray & data, ...
    

    Possibly functions in point one will encode data to another(text) encoding. Then try to convert QChar* from QString::data to QByteArray. Or write that QChar's into file and read QPixmap from file.