[Qt-interest] Creating QPixmap from QByteArray causes segfault [SOLVED]
Mandeep Sandhu
mandeepsandhu.chd at gmail.com
Wed May 5 07:52:17 CEST 2010
On Wed, May 5, 2010 at 1:00 AM, Malyushytsky, Alex <alex at wai.com> wrote:
>>> Is there a way I can instantiate QPixmap's in a non-GUI app?
>
> You can use QImage instead. It does not require GUI.
I could. But I'm writing a helper/util class which will be used in a
GUI app. So in the actual app there won;t be an issue, it's just that
when I want to test it out...I don;t want to write a GUI app!!! :)
Thanks,
-mandeep
>
> Alex
>
> -----Original Message-----
> From: qt-interest-bounces at trolltech.com [mailto:qt-interest-bounces at trolltech.com] On Behalf Of Mandeep Sandhu
> Sent: Monday, May 03, 2010 9:56 PM
> To: qt-interest at trolltech.com
> Subject: Re: [Qt-interest] Creating QPixmap from QByteArray causes segfault [SOLVED]
>
> This error was coming because I was trying to use a QPixmap in a
> console (non-GUI) application.
>
> It works fine if I use it in a GUI app.
>
> I'm actually writing a helper class, which was supposed to download an
> image along with some other metatdata and emit this result.
>
> For testing this class I thought I'd make a simple console app and see
> if it works. I did not want to go the GUI way since there really isn't
> any GUI part to test.
>
> Is there a way I can instantiate QPixmap's in a non-GUI app?
>
> Thanks,
> -mandeep
>
> On Mon, May 3, 2010 at 1:52 PM, Mandeep Sandhu
> <mandeepsandhu.chd at gmail.com> wrote:
>> Hi All,
>>
>> I'm trying to create a QPixmap from image data received from the
>> network. I have connected the QNAM's finshed signal to my slot, which
>> reads the data stream from the reply object (after all necessary error
>> checks) and tries creating a QPixmap object using the loadFromData()
>> API. However, this does not work and causes a seg fault! If I convert
>> the byte array to a const char* then it doesn't seg fault but gives
>> out the following error:
>>
>> Corrupt JPEG data: 1 extraneous bytes before marker 0xd9
>> JPEG datastream contains no image
>>
>> The reply->bytesAvailable() shown in the finished signal exactly
>> correspond to the number of bytes of the image. The image is not
>> corrupt as I can see it eog/gqview/display progs w/o any error.
>>
>> Here's the snippet that converts the data to image:
>>
>> void getData(QNetworkReply* reply) {
>> qDebug() << "Status code"
>> <<
>> reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt();
>>
>> if (reply->error() != QNetworkReply::NoError) {
>> qDebug() << "Error fetching data from" << reply->url();
>> return;
>> }
>>
>> qDebug() << "Bytes available" << reply->bytesAvailable();
>> if (reply->bytesAvailable() == 0) {
>> return;
>> }
>>
>> QByteArray bytes = reply->readAll();
>> qDebug() << "Rx'ed" << bytes.size();
>>
>> QPixmap pixi;
>> pixi.loadFromData(bytes.data());
>>
>> reply->deleteLater();
>> }
>>
>> I'm sure ppl have done this before and got it working.
>>
>> Any clues as to what could be going wrong?
>>
>> Thanks,
>> -mandeep
>>
>
> _______________________________________________
> Qt-interest mailing list
> Qt-interest at trolltech.com
> http://lists.trolltech.com/mailman/listinfo/qt-interest
>
>
> ---------------------------------------------------------------------------------------------------
> 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.”
>
> _______________________________________________
> Qt-interest mailing list
> Qt-interest at trolltech.com
> http://lists.trolltech.com/mailman/listinfo/qt-interest
>
More information about the Qt-interest-old
mailing list