Results 1 to 5 of 5

Thread: Why a Qwidget extended class does not receive parent ?

  1. #1
    Join Date
    Sep 2010
    Posts
    654
    Thanks
    56
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default Why a Qwidget extended class does not receive parent ?

    Is a very basic QT question :
    At adressbook example I see :

    Qt Code:
    1. at h : class NewAddressTab : public QWidget ()
    2. at cpp : NewAddressTab::NewAddressTab(QWidget *parent){...}
    To copy to clipboard, switch view to plain text mode 

    Why it is not neccesary to pass parent ?
    Thanks

  2. #2
    Join Date
    Feb 2011
    Location
    Latvia
    Posts
    139
    Thanks
    24
    Thanked 6 Times in 6 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Why a Qwidget extended class does not receive parent ?

    If I understand correctly - In this example NewAddressTab is subclassing QWidget, why would it need a parent?
    It has no parent, cause it is the main widget
    I cannot be sure though, that anything i said is true...

  3. #3
    Join Date
    Sep 2010
    Posts
    654
    Thanks
    56
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Why a Qwidget extended class does not receive parent ?

    In the sense of, for example, another element extending Qtabwidget is written :
    Qt Code:
    1. AddressWidget::AddressWidget(QWidget *parent) : QTabWidget(parent) {... }
    To copy to clipboard, switch view to plain text mode 
    Why then NewAddresTab are not like this :
    Qt Code:
    1. NewAddressTab::NewAddressTab(QWidget *parent) : QWidget (parent) {...}
    To copy to clipboard, switch view to plain text mode 
    ????

  4. #4
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,714
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: Why a Qwidget extended class does not receive parent ?

    Because this example is using QWidget's default constructor.
    You could pass the parent to QWidget if you wanted to.
    Its a matter of design decision based on the needs and uses of the class and software.
    I don't know why the trolls decided to declare the constructor with a parent, but not use it.
    Maybe originally it was meant to be destroyed by the parent as Qt classes do.
    This one however will not.
    ==========================signature=============== ==================
    S.O.L.I.D principles (use them!):
    https://en.wikipedia.org/wiki/SOLID_...iented_design)

    Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.

  5. #5
    Join Date
    Sep 2010
    Posts
    654
    Thanks
    56
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Why a Qwidget extended class does not receive parent ?

    Aha ! I understand.
    Thanks

Similar Threads

  1. How to signal when a Qwidget receive focus
    By franco.amato in forum Qt Programming
    Replies: 5
    Last Post: 5th February 2016, 16:33
  2. Replies: 1
    Last Post: 30th October 2010, 12:28
  3. Promoting the parent QWidget of a QWidget form
    By extrakun in forum Qt Tools
    Replies: 6
    Last Post: 16th April 2010, 14:19
  4. Do the layout class can receive the mouse event?
    By tszzp in forum Qt Programming
    Replies: 3
    Last Post: 23rd December 2009, 08:07
  5. Replies: 6
    Last Post: 3rd September 2008, 14:27

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
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.