QObject *obj; ... if ( /* obj is already instantiated */ ) { ; } else { obj = new QObject(); } My query is the condition of the if
1) Initialize your object pointer to NULL
2) Check for NULL in your if statement
QObject *obj = NULL; ... if ( obj != NULL ) { ; } else { obj = new QObject(); } obj is a member variable, then it should be initialized to 0/NULL/nullptr (take your pick) inside of your class's constructor, preferably in the initializer list.QObject *obj = 0; // ... if (!obj) obj = new QObject(); Note: Makes no guarantee obj is not a dangling pointer.
Use QPointer class. http://qt-project.org/doc/qt-4.8/qpointer.html#data
Whenever you call deleteLater(); it will set it to 0, than you can check it.
QPointer<QWidget> someWidget = 0;