your Button1 gets out of scope has the constructor exit. Try declaring it as a pointer.
your Button1 gets out of scope has the constructor exit. Try declaring it as a pointer.
__________________________________________________
My projects: calculator MathGraphica ; SuperEpicMegaHero game ; GooglePlay ; bitbucket ; github
Like my projects ? Buy me a kofi
Hi John, thanks, got it to work. Another question. I would like to create different types of buttons e.g. one that does something i.e. a function, one that outputs a value such as a letter or something... for this, I've written different initialiser lists. However I'm not sure whether this is enough to differentiate between the buttons upon instantiation. i.e. when I instantiate a function button, I want it to do a callback or send out a signal (Qt) that will then be received somewhere else and do something... so in this case all I want to do is specify that this button is a function button. However if I want to create a button that spits out a letter, I want to be able to assign a letter to that button upon instantiation/initialisation. Since the button has many different member variables, if I create a particular instance of a button, what happens to the unused class member variables? Do they acquire the default constructor values... do they remain uninitialised? Not sure if I've explained myself clearly enough.
Also... another question... lets say I create an object, is it possible to somehow pass the actual name of the object without needing to implement an additional member variable inside the class and declaring the name of that object upon instantiation of that object?
Last edited by Atomic_Sheep; 5th September 2012 at 10:42.
Not sure if I understand your questions, but you can define diferent constructors to define diferent member initialization/function calls when instantiating. If you are coding lots of diferent buttons perhaps you should consider using derived class buttons, to get a cleaner code and cleaner logic. If you do that, for the name of the object, you can avoid member variable, using just one method, something like this:
You will not need to set the object name at construction time, and will be able to get it whenever you want it.class ButtonA : public Button
{
public:
ButtonA();
virtual QString name() const{return "buttonA";}
.........
}
__________________________________________________
My projects: calculator MathGraphica ; SuperEpicMegaHero game ; GooglePlay ; bitbucket ; github
Like my projects ? Buy me a kofi
Ah yes good point, I actually started doing this this way a few months back when I started this problem and have since forgotten that I did it this way. I'll look into it again. My concern was simply the fact that some initialiser lists don't address various member variables or functions and that's what I was worried about since my understanding is that the default constructor isn't called if you call an overloaded one.
Bookmarks