Reputation: 14033
QObject *obj;
...
if ( /* obj is already instantiated */ ) {
;
} else {
obj = new QObject();
}
My query is the condition of the if
Upvotes: 3
Views: 3807
Reputation: 2923
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;
Upvotes: 0
Reputation: 4412
QObject *obj = 0;
// ...
if (!obj) obj = new QObject();
Note: Makes no guarantee obj
is not a dangling pointer.
Upvotes: 0
Reputation: 17535
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();
}
Upvotes: 5