Results 1 to 8 of 8

Thread: what does the constructor do here?

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Sep 2009
    Location
    UK
    Posts
    2,447
    Thanks
    6
    Thanked 348 Times in 333 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: what does the constructor do here?

    You can use whatever code you like in the constructor, in this case various widgets are added depending on the value to pass to the constructor.

    For example, if you pass ButtonWidget::ComboBoxes, then you get ComboBoxes, if you pass ( ButtonWidget::ComboBoxes | ButtonWidget::SpinBoxes) then you'll get boith ComboBoxes and SpinBoxes, etc.

    If you really wanted to you could write an entire application in your constructor, but its not best practice to do so.

  2. The following user says thank you to squidge for this useful post:

    LB4229 (21st June 2011)

  3. #2
    Join Date
    Jun 2011
    Posts
    3
    Thanks
    4

    Default Re: what does the constructor do here?

    thank you. I thought the constructor would be used only for initialization.
    Your explanation enlightens me.

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

    Default Re: what does the constructor do here?

    The constructor is only used for initialisation in the ButtonWidget. The 'widget' parameter is used to drive how the ButtonWidget is initialised using other methods (comboBoxes() etc.) in the class.

  5. The following user says thank you to ChrisW67 for this useful post:

    LB4229 (22nd June 2011)

  6. #4
    Join Date
    Mar 2011
    Location
    Hyderabad, India
    Posts
    1,882
    Thanks
    3
    Thanked 452 Times in 435 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows
    Wiki edits
    15

    Default Re: what does the constructor do here?

    Added to what squidge said, constructor is basically a special function which is called (automatically, compiler generates the required code) when object is created, you can do all the things in it which you could do in normal function, added to normal function constructors can take initialization list. Also there types of constructors like default constructor, copy constructor etc. which are beyond the scope of this post.

  7. The following user says thank you to Santosh Reddy for this useful post:

    LB4229 (22nd June 2011)

Similar Threads

  1. Replies: 13
    Last Post: 19th June 2011, 21:04
  2. class constructor
    By ^NyAw^ in forum Qt Programming
    Replies: 2
    Last Post: 5th December 2008, 18:25
  3. connect in constructor?
    By McKee in forum Qt Programming
    Replies: 4
    Last Post: 13th October 2007, 21:53
  4. QImage constructor
    By Lele in forum Qt Programming
    Replies: 2
    Last Post: 11th January 2007, 12:06
  5. What default constructor?
    By bitChanger in forum General Programming
    Replies: 5
    Last Post: 15th February 2006, 19:50

Tags for this Thread

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.