Results 1 to 4 of 4

Thread: Parentwidget doubt. Create new widgets with parent or not ?

Hybrid View

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

    Default Parentwidget doubt. Create new widgets with parent or not ?

    In case I dont need to do any particular thing with widgets, it is neccesary to create them always with parentwidget parameter?

    Another question, I have a custom widget, I create a Qframe, a layout for it, and 3 widgets (added to the layout)
    If a Qframe is the parent of a Qlayout and inside it I have the 3 widgets.... At the time of delete the whole custom widget have I to delete every widget or in case there are right parentwidget for everyone, is it right to delete only the main parentwidget ? (if not, then I dont know the meaning of givin parents... )
    Thanks.

  2. #2
    Join Date
    Jan 2012
    Location
    Argentina
    Posts
    167
    Thanks
    33
    Thanked 10 Times in 10 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Parentwidget doubt. Create new widgets with parent or not ?

    I guess not, that`s why by default if you dont pass a parent when creating an object, parent var is set to NULL.

    The most common problem that arouses when you DONT give a parent is that the user can, for example, click the parent Widget that is open. For example...your app has a Widget that export`s data and while the data is exporting nothing can be done/clicked because can cause crash of the app. For that purpose you have, for example, a Dialog with a progress bar that tell you how much time is left to finish the operation. If you dont give the Widget as a parent for the dialog then the user can change things of the Widget running and the information is going to be inconsistent. I know there are other ways of preventing that to happen but hope I could give you a hand.

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

    Default Re: Parentwidget doubt. Create new widgets with parent or not ?

    Thanks K. However I still have a question about deleting.

  4. #4
    Join Date
    Oct 2010
    Location
    Berlin, Germany
    Posts
    358
    Thanks
    18
    Thanked 68 Times in 66 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Parentwidget doubt. Create new widgets with parent or not ?

    Quote Originally Posted by tonnot View Post
    Another question, I have a custom widget, I create a Qframe, a layout for it, and 3 widgets (added to the layout)
    If a Qframe is the parent of a Qlayout and inside it I have the 3 widgets.... At the time of delete the whole custom widget have I to delete every widget or in case there are right parentwidget for everyone, is it right to delete only the main parentwidget ? (if not, then I dont know the meaning of givin parents... )
    As already mentioned in the other thread, you don't have to delete widgets manually that are arranged in a layout. when you delete your custom widget, the layout gets deleted. Deleting the layout deletes all contained widgets automatically.

    Felix

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

    tonnot (13th February 2012)

Similar Threads

  1. Replies: 2
    Last Post: 25th November 2011, 00:47
  2. Replies: 3
    Last Post: 19th March 2011, 15:01
  3. Need 2 widgets without a parent to comunicate
    By boblatino in forum Qt Programming
    Replies: 28
    Last Post: 2nd August 2010, 14:18
  4. Replies: 4
    Last Post: 1st May 2009, 11:00
  5. Replies: 3
    Last Post: 27th November 2008, 23:57

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.