Question

i try to check if QPixmap is initialized, when i try to check using :

QPixmap pix;

    if(pix.data_ptr())
    or
    if(pix != null)

where pix is member of QPixmap type .

all gives me :

Access violation reading location 0x0000000c.

how can i check in code if pix is null ?

Was it helpful?

Solution 2

The only case when non-pointer QPixmap could be not initialized is when code like this is executed:

QPixmap getPixmap()
{
 // no return statement here
}

QPixmap pix = getPixmap();
// now pix is invalid but .isNull() will return false

I've had similar issues with no-initialized QStrings.

OTHER TIPS

Use the isNull() function,

if(!item->pix.isNull())
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top