首页| 论坛| 消息

标题:请教new的时候这个this有无必要还是都可以呢?
作者:ustone
日期:2018-06-08 12:59
内容:


#1 [kaon 06-08 14:25]
http://doc.qt.io/qt-5/qaction.html#QAction-1
Constructs an action with some text and parent. If parent is an action group the action will be automatically inserted into the group.
#2 回 kaon 的帖子 [ustone 06-08 17:33]
kaon:http://doc.qt.io/qt-5/qaction.html#QAction-1
Constructs an action with some text and parent. If parent is an action group the action will be automatically inserted into the group. (2018-06-08 14:25) 
这个我看懂了,但是我的问题还是没有解决,fileMenu->addAction(openAct);会把fileMenu作为openAct的parent吗?如果这样,openAct就有两个parent了?
#3 [kaon 06-08 18:24]
http://doc.qt.io/qt-5/qwidget.html#addAction
The ownership of action is not transferred to this QWidget.
#4 回 kaon 的帖子 [ustone 06-08 21:45]
kaon:http://doc.qt.io/qt-5/qwidget.html#addAction
The ownership of action is not transferred to this QWidget.
 (2018-06-08 18:24) 
那代码就对了。
QAction的构造函数,那个参数是parent,
QAction(const QString &text, QObject *parent = nullptr)
构造的时候parent同时也是owner吗?
#5 [ustone 06-08 21:50]
我查了一下,
void QLayout::addWidget(QWidget *w)
Adds widget w to this layout in a manner specific to the layout. This function uses addItem().
void QLayout::addItem(QLayoutItem *item)
。。。
Note: The ownership of item is transferred to the layout, and it's the layout's responsibility to delete it.
看起来感觉跟addAction不一致,是不是这个道理,action可以被多个widget添加(比如菜单、工具栏、右键菜单等),所以ownership不转移?

<< 1 2 >> (1/2)

回复 发表
主题 版块