Results 1 to 3 of 3

Thread: QImage to QString

  1. #1
    Join Date
    Aug 2008
    Posts
    134
    Thanks
    10
    Thanked 3 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default QImage to QString

    Hi,
    I need to convert the QImage to QString and vise versa. before converting i need to compress the data. to compress i am using qcompress() and returns QByteArray.
    qcompress() successfully returns compressed byteArray . But when i convert byteArray to QString , the string will be always empty. This may be because QByteArray object contain null character. How can i convert QByteArray to QString????
    I used
    QImage curImage("c:/file");
    QByteArray ba;
    QBuffer buffer(&ba);
    buffer.open(QIODevice::WriteOnly);
    curImage.save(&buffer, "BMP");
    QByteArray arr = qCompress(buffer.buffer(),5);
    QString str = QString(arr);

    when i use last statement str will be null... but arr will have contents....

  2. #2
    Join Date
    Dec 2006
    Posts
    849
    Thanks
    6
    Thanked 163 Times in 151 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: QImage to QString

    try QByteArray::toBase64()
    Qt Code:
    1. QString str = arr.toBase64();
    To copy to clipboard, switch view to plain text mode 

  3. #3
    Join Date
    Aug 2008
    Posts
    134
    Thanks
    10
    Thanked 3 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QImage to QString

    Thank you... its working fine... when i convert QString to QByteArray by means of fromHex(), it converts to QByteArray.
    But when i save the image using the contents of QbyteArray, it will be black. Image maintains the dimensions , but saved image will be black..

    Can anyone tell me how can i convert it to proper format???

Similar Threads

  1. Custom Model Advice Requested
    By mclark in forum Qt Programming
    Replies: 3
    Last Post: 18th September 2008, 16:26
  2. easiest Way QString can do
    By baray98 in forum Qt Programming
    Replies: 12
    Last Post: 15th April 2008, 20:49
  3. Convert from iso-8859-1 to... Something else :-)
    By Nyphel in forum Qt Programming
    Replies: 4
    Last Post: 7th March 2007, 17:59
  4. Converting QString to unsigned char
    By salston in forum Qt Programming
    Replies: 3
    Last Post: 24th April 2006, 22:10
  5. [SOLVED] Widget plugin ... how to ?
    By yellowmat in forum Newbie
    Replies: 10
    Last Post: 29th January 2006, 20:41

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.