franco.amato
15th October 2010, 18:22
Hi to all,
I know that when I create a new widget ( for example a QPushButton ) I need to pass the parent widget to the ctor, so the new created widget can be deleted when the parent is deleted.
What is not so clear for me is ( looking at the documentation ) is why the parent is not passed to the widget when it's added to a layout.
for example this code:
QWidget *window = new QWidget;
QPushButton *button1 = new QPushButton("One");
QPushButton *button2 = new QPushButton("Two");
QPushButton *button3 = new QPushButton("Three");
QPushButton *button4 = new QPushButton("Four");
QPushButton *button5 = new QPushButton("Five");
QVBoxLayout *layout = new QVBoxLayout;
layout->addWidget(button1);
layout->addWidget(button2);
layout->addWidget(button3);
layout->addWidget(button4);
layout->addWidget(button5);
window->setLayout(layout);
window->show();
is part of the QVBoxLayout documentation.
I can not see where the parent widget is passed to the buttons and layout. Does it generate memory leaks errors?
Maybe is my mistake or maybe the Qt developers doen't give much attention to the examples, it this last case it would be better that Qt developers post correct code without errors.
Best Regards
I know that when I create a new widget ( for example a QPushButton ) I need to pass the parent widget to the ctor, so the new created widget can be deleted when the parent is deleted.
What is not so clear for me is ( looking at the documentation ) is why the parent is not passed to the widget when it's added to a layout.
for example this code:
QWidget *window = new QWidget;
QPushButton *button1 = new QPushButton("One");
QPushButton *button2 = new QPushButton("Two");
QPushButton *button3 = new QPushButton("Three");
QPushButton *button4 = new QPushButton("Four");
QPushButton *button5 = new QPushButton("Five");
QVBoxLayout *layout = new QVBoxLayout;
layout->addWidget(button1);
layout->addWidget(button2);
layout->addWidget(button3);
layout->addWidget(button4);
layout->addWidget(button5);
window->setLayout(layout);
window->show();
is part of the QVBoxLayout documentation.
I can not see where the parent widget is passed to the buttons and layout. Does it generate memory leaks errors?
Maybe is my mistake or maybe the Qt developers doen't give much attention to the examples, it this last case it would be better that Qt developers post correct code without errors.
Best Regards