0

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 ?

user63898
  • 29,839
  • 85
  • 272
  • 514
  • 1
    What data type is `item`? – SingerOfTheFall Feb 27 '13 at 13:21
  • it is general that in its constructor i set up dummy QPixmap object my question is how to check QPixmap if it initialized or not – user63898 Feb 27 '13 at 13:23
  • I think you need to provide a clearer description of what you're trying to do. @cartman told you how to check if a QPixmap is initialised, but it doesn't seem that that was really your question. If the small amount of code you have given is causing a crash it's because item wasn't initialised. – Dan Milburn Feb 27 '13 at 13:39
  • forget the item , i want to check only if pix initialized i updated the question – user63898 Feb 27 '13 at 13:45
  • Your question doesn't make much sense. If you declare `pix` like that, you cannot compare it to null. `pix` just cannot be null (or uninitialized). Please show code that compiles. –  Feb 27 '13 at 15:37

2 Answers2

3

Use the isNull() function,

if(!item->pix.isNull())
ismail
  • 46,010
  • 9
  • 86
  • 95
  • no , its only working if the QPixmap initialized with object dummy object . but here i want to check if the QPixmap is initialized or not with this dummy object – user63898 Feb 27 '13 at 13:27
  • Since your "pix" is not a pointer, it'll be always be initialized with the dummy object. – ismail Feb 27 '13 at 13:32
  • no its not , i have here case where somehow i dont know how its only get the deceleration without setting the dummy object. but its doesn't matter . i want to check if its initialized – user63898 Feb 27 '13 at 13:34
  • forget the item , i want to check only if pix initialized i updated the question – user63898 Feb 27 '13 at 13:44
  • In which case this is the correct answer and you should accept it. – Dan Milburn Feb 27 '13 at 13:53
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.