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 ?

有帮助吗?

解决方案 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.

其他提示

Use the isNull() function,

if(!item->pix.isNull())
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top