Results 1 to 7 of 7

Thread: Initialiser list with QObject

  1. #1
    Join Date
    Jun 2011
    Posts
    203
    Qt products
    Qt4
    Platforms
    MacOS X Windows
    Thanks
    7
    Thanked 4 Times in 3 Posts

    Default Initialiser list with QObject

    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:

    Qt Code:
    1. class Button : public QObject
    2. {
    3. Q_OBJECT
    To copy to clipboard, switch view to plain text mode 

    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

    Qt Code:
    1. Button::Button(QObject *parent) :
    2. QObject(parent)
    To copy to clipboard, switch view to plain text mode 

    but that didn't work.

  2. #2
    Join Date
    Apr 2012
    Posts
    14
    Qt products
    Qt4
    Platforms
    MacOS X Windows
    Thanked 1 Time in 1 Post

    Default Re: Initialiser list with QObject

    Write full declaration of your class.

  3. #3
    Join Date
    Jun 2011
    Posts
    203
    Qt products
    Qt4
    Platforms
    MacOS X Windows
    Thanks
    7
    Thanked 4 Times in 3 Posts

    Default Re: Initialiser list with QObject

    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.

  4. #4
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Wiki edits
    17

    Default Re: Initialiser list with QObject

    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.

  5. #5
    Join Date
    Jun 2011
    Posts
    203
    Qt products
    Qt4
    Platforms
    MacOS X Windows
    Thanks
    7
    Thanked 4 Times in 3 Posts

    Default Re: Initialiser list with QObject

    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 .

  6. #6
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Wiki edits
    17

    Default Re: Initialiser list with QObject

    Quote Originally Posted by Atomic_Sheep View Post
    Yep, Melb, I'm guessing my incessant use of s instead of z tipped you off .
    Dead give away, although you could have been Kiwi or a Pom.

  7. #7
    Join Date
    Jun 2011
    Posts
    203
    Qt products
    Qt4
    Platforms
    MacOS X Windows
    Thanks
    7
    Thanked 4 Times in 3 Posts

    Default Re: Initialiser list with QObject

    Oh I see... forgot about those options.

Similar Threads

  1. QObject::MetaObject()
    By pkj in forum Qt Programming
    Replies: 3
    Last Post: 4th June 2011, 11:41
  2. Replies: 1
    Last Post: 23rd April 2011, 18:33
  3. List View with sections for alphabetialy sorted list
    By woodtluk in forum Qt Programming
    Replies: 4
    Last Post: 12th October 2010, 12:50
  4. Replies: 1
    Last Post: 31st October 2007, 15:14
  5. help on QObject::tr()
    By sincnarf in forum Qt Programming
    Replies: 1
    Last Post: 16th October 2007, 08:52

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Qt is a trademark of The Qt Company.