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

Manuel Klemenz m.klemenz at gmx.at
Mon Jul 19 21:50:57 CEST 2010


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.

Oh, and it'd be good practice to give a parent to the new image, too:
A() { m_image = QImage(this);}

-- 
Cheers,
Manuel Klemenz
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 490 bytes
Desc: This is a digitally signed message part.
Url : http://lists.qt-project.org/pipermail/qt-interest-old/attachments/20100719/398b8db8/attachment.bin 


More information about the Qt-interest-old mailing list