سؤال

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