[Qt-interest] QImage Null Pointer - Do not understand what is wrong

Michael Jackson mike.jackson at bluequartz.net
Mon Jul 19 21:57:59 CEST 2010


On 7/19/10 3:45 PM, in article 201007192145.34503.m.klemenz at gmx.at, "Manuel
Klemenz" wrote:

> On Monday 19 July 2010 20:16:30 Michael Jackson wrote:
>> I have something like the following code:
>> 
>> Class A
>> {
>>     public:
>>     A() { m_image = QImage(); }
>> 
>>     QImage getImage() {
>>         return m_image; <== Crashes on this line
>>     }
>> 
>> private:
>>     QImage m_image;
>> };
>> 
>> Void somefunction()
>> {
>> // a is an instance variable of type A and is declared as
>> // A* a;
>> // and initialized in the constructor of the class as
>> // a = new A;
>>   QImage image = a->getImage();
>>   If (image.isNull() )
>>   {
>>     // Do Something
>>   }
>> }
>> 
>> The problem seems to be that down in QImage(QImage& image) something is not
>> quite right and I am getting an EXEC_BAD_ACCESS and my program crashes.
>> This is on OS X 10.5.8 with Qt 4.6.2 (self built) with Cocoa. Compiled as
>> i386 for debugging.
>> 
>> The QImage code is the following:
>> QImage::QImage(const QImage &image)
>> 
>>     : QPaintDevice()
>> 
>> {
>>     d = image.d; <== Error occurs here.
>>     if (d)
>>         d->ref.ref();
>> }
>> 
>> Any help in my usage would be much appreciated.
> 
> not sure, but I think that the problem here is that the attribute m_image is
> defined after its first usage (inline constructor)...
> If I'm not completely wrong, something like this should work:
> 
> Class A
> {
> private:
>     QImage m_image;
> 
> public:
>     A() { m_image = QImage(); }
> 
>     QImage getImage() {
>         return m_image; <== Crashes on this line
>     }
> };
> 
> Position matters ;)

Sorry for the noise. I was not interpreting the debugger stack correctly.
The error appears further up the stack where a NULL pointer is. Again sorry
for the noise. The original code as I posted works just the way it should.

THanks
Mike Jackson




More information about the Qt-interest-old mailing list