Results 1 to 10 of 10

Thread: Question about qt objects deletion

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Feb 2014
    Posts
    8
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: Question about qt objects deletion

    MyForm(QWidget *parent = 0) : QWidget(parent) i sow this expression many times and i didn't get it ....can you explaine please
    and what do you mean by the class already deletes its children
    and last i am sorry about those too many questions i am a confused newbie

  2. #2
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Question about qt objects deletion

    Quote Originally Posted by MI View Post
    MyForm(QWidget *parent = 0) : QWidget(parent) i sow this expression many times and i didn't get it ....can you explaine please
    This is a constructor of a C++ class called MyForm.
    It takes one argument of type QWidget*, named parent, and has a default value of 0.
    The parent argument is passed on to the base class constructor.

    Quote Originally Posted by MI View Post
    and what do you mean by the class already deletes its children
    Because you are passing "this" as the parent of the children. QObject subclasses such as QWidget and thus MyForm delete their children when they are deleted.

    Cheers,
    _

  3. #3
    Join Date
    Feb 2014
    Posts
    8
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: Question about qt objects deletion

    new question : by doing this " MyForm(QWidget *parent = 0) : QWidget(parent) " what are we really saying to the compiler ...
    and please putup with me

  4. #4
    Join Date
    Oct 2013
    Posts
    41
    Thanks
    1
    Thanked 8 Times in 7 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Question about qt objects deletion

    Quote Originally Posted by MI View Post
    new question : by doing this " MyForm(QWidget *parent = 0) : QWidget(parent) " what are we really saying to the compiler ...
    and please putup with me
    Whatever widget you create an instance of this form in, when you call "MyForm myForm(this);" You are saying that the widget you called it from is the parent of myForm. When that parent gets deleted, it will call the destructor on all of its children causing a chain reaction.

  5. #5
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Question about qt objects deletion

    sulliwk06 already explained the runtime behavior created by this so here the "what are we saying to the compiler" bit:

    we tell the compiler that instance of class MyForm can be constructed with zero or one argument of type QWidget*.

    If no argument is passed to the constructor, then a null pointer should be assumed.

    The given value (either the argument or the null pointer) should be uses as the argument of the invocation of the base class constructor.

    Cheers,
    _

  6. #6
    Join Date
    Feb 2014
    Posts
    8
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: Question about qt objects deletion

    Big thanks to every one who helped me

Similar Threads

  1. QSerialDevice enumerator deletion question
    By marcvanriet in forum Qt Programming
    Replies: 4
    Last Post: 28th December 2011, 01:48
  2. Replies: 3
    Last Post: 9th January 2010, 15:47
  3. Controling the deletion of objects?
    By mooreaa in forum Qt Programming
    Replies: 3
    Last Post: 4th July 2008, 18:08
  4. Replies: 7
    Last Post: 18th July 2006, 21:33

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.