[Qt-interest] Convert from a QPixmap into a QByteArray, and back

Malyushytsky, Alex alex at wai.com
Wed May 19 02:21:42 CEST 2010


Have you tried using
QDataStream & operator>> ( QDataStream & stream, QPixmap & pixmap )
instead of loadFromData(bytes->data());

This functions might assume different format of data written.

Alex


From: qt-interest-bounces at trolltech.com [mailto:qt-interest-bounces at trolltech.com] On Behalf Of Gabriele Kahlout
Sent: Tuesday, May 18, 2010 2:54 PM
To: qt-interest at trolltech.com
Subject: [Qt-interest] Convert from a QPixmap into a QByteArray, and back

Hello,

In the process of debugging I've found myself unable to assert the following code:
int main(int argc, char *argv[])
{
    QApplication a(argc, argv);
    const QPixmap screen = QPixmap::grabWindow(QApplication::desktop()->winId());
    QByteArray *bytes = new QByteArray();
    QDataStream out(bytes, QIODevice::WriteOnly);
    out << screen;
    QPixmap* screen1 = new QPixmap();
    screen1->loadFromData(bytes->data());
    std::cout << screen1->save("7777.png", "PNG") << endl;
    std::cout << screen.save("6666.png", "PNG") << endl;
    return a.exec();
}

All I'm doing is trying to convert from a QPixmap into a QByteArray, and back. Although the code is mostly verbatim from QPixmap and QDataStream, it doens't work. Indeed screen1 fails to save into 7777.png.

Your help, fixing this code, is greatly appreciated.

--
Regards,
K. Gabriele

--- unchanged since 25/1/10 ---
P.S. Unless a notification (LON), please reply either with an answer OR with " ACK" appended to this subject within 48 hours. Otherwise, I might resend.
In(LON, this) ∨ In(48h, TimeNow) ∨ ∃x. In(x, MyInbox) ∧ IsAnswerTo(x, this) ∨ (In(subject(this), subject(x)) ∧ In(ACK, subject(x)) ∧ ¬IsAnswerTo(x,this)) ⇒ ¬IResend(this).

Also note that correspondence may be received only from specified a priori senders, or if the subject of this email ends with a code, eg. -LICHT01X, then also from senders whose reply contains it.
∀x. In(x, MyInbox) ⇒ In(senderAddress(x), MySafeSenderList) ∨ (∃y. In(y, subject(this) ) ∧ In(y,x) ∧ isCodeLike(y, -LICHT01X) ).


---------------------------------------------------------------------------------------------------
Weidlinger Associates, Inc. made the following annotations.

“This message and any attachments are solely for the intended recipient and may contain confidential or privileged information. If you are not the intended recipient, any disclosure, copying, use, or distribution of the information included in this message and any attachments is prohibited. If you have received this communication in error, please notify us by reply e-mail and immediately and permanently delete this message and any attachments. Thank you.”

“Please consider our environment before printing this email.”




More information about the Qt-interest-old mailing list