PDA

View Full Version : Initialiser list with QObject



Atomic_Sheep
15th May 2012, 15:19
Hi guys, I'm playing around with composition and inheritance for the first time and I'm hitting a bit of a problem.

From my understanding, to be able to have an object emit a signal and receive signals i.e. for that it must have slots, it must inherit QObject.

So I created my own class and included the Q_OBJECT macro:


class Button : public QObject
{
Q_OBJECT

However, I would also like this button to include other classes which outline the button position and other attributes in their own classes. When I created the initialiser list in the header file, the variables which I assigned to the Button members explicitly i.e. after the : symbol, spit out an error upon building...


'position' was not declared in this scope.

How do I solve this problem?

I tried simply adding my initialiser list after the


Button::Button(QObject *parent) :
QObject(parent)

but that didn't work.

AlekseyOk
15th May 2012, 15:41
Write full declaration of your class.

Atomic_Sheep
16th May 2012, 08:14
Could you please elaborate a little? I wrote the declaration for the class in its own header file and linked/included it into the class header file that I want to use as its parent.

ChrisW67
17th May 2012, 00:59
The error message implies that you are trying to initialise (BTW, are you Aussie?) a member variable called "position" that does not exist in the class. We cannot help specifically because you do not show us the declaration of the class and the offending lines.

Atomic_Sheep
17th May 2012, 17:48
Yep, I figured out the problem, I copied from another site not really understanding what it was doing and when I went back over it, I figured out why I totally messed up the initialisations.

Yep, Melb, I'm guessing my incessant use of s instead of z tipped you off :D.

ChrisW67
17th May 2012, 23:34
Yep, Melb, I'm guessing my incessant use of s instead of z tipped you off :D.
Dead give away, although you could have been Kiwi or a Pom.

Atomic_Sheep
20th May 2012, 12:26
Oh I see... forgot about those options.