[Qt-interest] QPainter segmentation fault on Linux

Samuel Rødal sroedal at trolltech.com
Fri Feb 20 15:58:25 CET 2009


Davide wrote:
> Hi,
> 
> On Fri, Feb 20, 2009 at 12:48 PM, Srdjan Todorovic
> <todorovic.s at googlemail.com> wrote:
>> How big is Image.data?
> 
> typedef struct{
>     ushort width;
>     ushort height;
>     uchar data[960000];
> } TImage;
> 
>>  Is it a valid pointer?
> 
> Yes, Image is declared as public in my class:
> TImage Image;
> 
>> What value is Image.width?
>> What value is Image.height?
> 
> 80 and 60. I've checked them with the Debugger just a moment before
> the program crashes.
> 
>> Have you checked to see what QPainter::drawRect() does internally?
> 
> Not yet but I'm going to.
> 
>> Have you checked to see if you have a segfault on another Linux machine?
> 
> Yes, I tested it on 2 different machines and the results were the same.
> 
>> Does this code work reliably on a different (earlier) version of Qt?
> 
> I don't know exactly, I tested the code in windows with Qt 4.4.0,
> 4.4.3 and 4.5b and it work perfectly.
> 
> Regards
> 

I tried to reproduce it here with the following code:

#include <QtGui>
#include <QtDebug>

int main(int argc, char **argv)
{
     QApplication app(argc, argv);

     ushort width = 80;
     ushort height = 60;
     ushort data[960000];
     QImage *img = new QImage((uchar *)data, width, height, 
QImage::Format_RGB32);
     QPainter p;
     p.begin(img);
     p.setPen((Qt::GlobalColor)(Qt::cyan));
     p.drawRect(2, 2, 20, 20);
     p.end();
}

But it doesn't crash for me. Does this example crash for you?

--
Samuel



More information about the Qt-interest-old mailing list