gpt4 book ai didi

c++ - 内存管理 - addwidget 是否分配父级

转载 作者:搜寻专家 更新时间:2023-10-31 00:36:49 24 4
gpt4 key购买 nike

假设我有这样的东西

void someClass::start()
{
QLabel* sb = new QLabel();
sb->setText("Hello World");
ui.verticalLayout->addWidget(sb);
}

addWidget 是否使 sb 成为 someClass 的子级,以便在我删除 someClass 时 sb 也被删除?如果这是真的,我怎么知道通常哪些方法将父对象分配给对象?

最佳答案

来自 http://qt-project.org/doc/qt-4.8/layout.html :

When you use a layout, you do not need to pass a parent when constructing the child widgets. The layout will automatically reparent the widgets (using QWidget::setParent()) so that they are children of the widget on which the layout is installed.

关于c++ - 内存管理 - addwidget 是否分配父级,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20853816/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com