Signal-Slot, object instances
I am using a designer..and I was curious whether one could make a signal slot connection without making a instance of a object but declaring a object..
MyObj *obj;
connect(obj,SIGNAL(),this,SLOT());
obj=new MyObj();
just curious whether this would be valid
Re: Signal-Slot, object instances
What actually do you mean?
In designer genearated files i never see something like that :rolleyes:
Re: Signal-Slot, object instances
Well in designer you don't actually have the
MyObj *obj;
it is written at the public member Object explorer.
Now, generally before using the object we need to create a instance for it..I am asking can we use the object without creating its instance in a signal slot connection ..and what may its consequences be.
Re: Signal-Slot, object instances
Code:
MyObj *obj;
connect(obj,SIGNAL(),this,SLOT());
This will crash.
You are passing an uninitialized pointer to connect(). If you're lucky obj is initialized with 0 and connect() checks for 0-pointers, but generally accessing an uninitialized object is simply shooting yourself in the foot.