Derek
Derek

Reputation: 11905

QPixmap::fromImage() gives segmentation fault in QX11PixmapData

I have written some code that looks more or less like this:

QVector<QRgb> colorTable(256);
 QImage *qi = new QImage(lutData, imwidth,imheight, QImage::Format_Indexed8);

 while (index < 256)
 {
         colorTable.replace(index, qRgb(2552,255, 255));
         index++;
 }
 qi->setColorTable(colorTable);


 QPixmap p(QPixmap::fromImage(*qi,Qt::AutoColor));

so lutData (unsigned char) is my indexes into the colorTable. This crashes on the last line of the snippet, and the actual line is in a library I cant see source to called QX11PixmapData. What am I doing wrong to cause this crash, or is it a Qt Bug?

I am running CentOS 5.5 if that matters.

Thanks!

Upvotes: 0

Views: 2048

Answers (1)

Stephen Chu
Stephen Chu

Reputation: 12832

The QImage constructor you called is:

QImage::QImage ( const uchar * data, int width, int height, Format format )

Which requires the scanline data to be 32-bit aligned. So make sure it is and also has enough bytes in it. Or you can use:

QImage::QImage ( uchar * data, int width, int height, int bytesPerLine, Format format )

Which allows specification of bytes per scanline without being 32-bit aligned. So you can call it this way:

QImage *qi = new QImage(lutData, imwidth, imheight, imwidth, QImage::Format_Indexed8);

Since for a index color image, the scanline bytes is the same as the width.

Upvotes: 3

Related Questions