Results 1 to 3 of 3

Thread: constructor declaration

  1. #1
    Join Date
    Aug 2009
    Location
    coimbatore,India
    Posts
    314
    Thanks
    37
    Thanked 47 Times in 43 Posts
    Qt products
    Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default constructor declaration

    Dear experts,

    Just a quick question,

    1) In constructor declaration, which is better

    Qt Code:
    1. myClass(QWidget *pParent = 0)
    To copy to clipboard, switch view to plain text mode 
    or
    Qt Code:
    1. myClass(QWidget *pParent = NULL)
    To copy to clipboard, switch view to plain text mode 

    2)and shall I check like the following? (comparing integer and pointer?)
    Qt Code:
    1. if ( 0 == qApp->activeModalWidget())
    To copy to clipboard, switch view to plain text mode 


    Thanks,
    Bala

  2. #2
    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: constructor declaration

    better be consistent, use 0, both in ctor and comparison.

    If need to use NULL macro due to existing code, use NULL for comparing all the objects which are based on existing code. What I mean to is be constant in using them, i.e don't mix them.

    eq: if class A ctor is using 0, then compare all objects / pointers of class A with 0
    if class B ctor is using NULL, then compare all objects / pointer of class B with NULL

  3. #3
    Join Date
    Aug 2009
    Location
    coimbatore,India
    Posts
    314
    Thanks
    37
    Thanked 47 Times in 43 Posts
    Qt products
    Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: constructor declaration

    Quote Originally Posted by Santosh Reddy View Post
    better be consistent, use 0, both in ctor and comparison.

    If need to use NULL macro due to existing code, use NULL for comparing all the objects which are based on existing code. What I mean to is be constant in using them, i.e don't mix them.

    eq: if class A ctor is using 0, then compare all objects / pointers of class A with 0
    if class B ctor is using NULL, then compare all objects / pointer of class B with NULL
    Thanks for the reply,

    So, its safe to use
    Qt Code:
    1. if ( 0 == qApp->activeModalWidget())
    To copy to clipboard, switch view to plain text mode 

    Thanks,
    Bala

Similar Threads

  1. static declaration
    By jhearon in forum Qt Programming
    Replies: 1
    Last Post: 18th February 2008, 21:37
  2. QtXml: xml declaration
    By Gopala Krishna in forum Newbie
    Replies: 1
    Last Post: 2nd June 2007, 12:12
  3. Declaration problems
    By scarvenger in forum Qt Programming
    Replies: 1
    Last Post: 7th May 2007, 02:05
  4. Declaration not working
    By kenny_isles in forum Newbie
    Replies: 1
    Last Post: 1st March 2007, 10:13
  5. Why forward declaration ?
    By probine in forum General Programming
    Replies: 3
    Last Post: 26th January 2007, 18:22

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.