Why no signals for stack objects?
-
I always used only Qt objects with dynamic allocation, but this time tried simple create it on the stack, like in old days. And found that strange behavior, that i cant connect anything, simply no signals from my QPushButton if it created like:
QPushButton butt;Then i connect if all nicely created as:
QPushButton *butt = new QPushButton(this); -
I always used only Qt objects with dynamic allocation, but this time tried simple create it on the stack, like in old days. And found that strange behavior, that i cant connect anything, simply no signals from my QPushButton if it created like:
QPushButton butt;Then i connect if all nicely created as:
QPushButton *butt = new QPushButton(this);@Engelard said in Why no signals for stack objects?:
And found that strange behavior, that i cant connect anything, simply no signals from my QPushButton if it created like
You're doing something wrong. Probably the
connect. Stack vs heap has nothing to do with signals/slots. -
Found it. I never notice, but in parameters in connection there is required a reference to objects, not object itself(as it was in my case):
connect(&butt, SIGNAL(clicked(bool)), -
@aha_1980 after year of c++ i still can't see what the difference. Functionality is absolutely the same in our case.
@Engelard said in Why no signals for stack objects?:
after year of c++ i still can't see what the difference. Functionality is absolutely the same in our case.
- Some things can be done with references but not with pointers.
- Many things can be done with pointers but not with references.
-
@Engelard said in Why no signals for stack objects?:
after year of c++ i still can't see what the difference. Functionality is absolutely the same in our case.
- Some things can be done with references but not with pointers.
- Many things can be done with pointers but not with references.
-
Sure there is a difference.
connect()expects a pointer to an object, therefore you have to give&objectwhich is equivalent to the address ofobject. You probably never noted before, because you had a pointer to the object created bynew, which you therefore could directly pass toconnect.