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

Manuel Klemenz m.klemenz at gmx.at
Mon Jul 19 21:45:23 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.

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 ;)

-- 
Cheers,
Manuel Klemenz
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.qt-project.org/pipermail/qt-interest-old/attachments/20100719/077b388b/attachment.html 
-------------- 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/077b388b/attachment.bin 


More information about the Qt-interest-old mailing list