jxl786715414jxl
PenNameLuXun
2017-01-19 04:05

Qt QTreeWidget setItemWidget疑问

  • 继承

从QTreeWidget继承写的 CHddsTreeWidget在树上添加按钮
void CHddsTreeWidget::AddToolBtn()
{
for (int j = 0; j < topLevelItemCount(); j++)
{
QTreeWidgetItem rootitem = topLevelItem(j);
if (j == 0)
{
QTreeWidgetItem
AddImageIterm = new QTreeWidgetItem(rootitem);
CTreeToolBtn* pAddImageBtn = new CTreeToolBtn(eAddImageBtn,AddImageIterm);
SetItemIcon(AddImageIterm,0);
}
else if (1 == j)
{
int DiskNum = rootitem->childCount();
for (int i = 0; i < DiskNum;++i)
{
QTreeWidgetItem * pDisk = rootitem->child(i);
QTreeWidgetItem* pBtnItem = new QTreeWidgetItem(pDisk);
CTreeToolBtn* pBtn = new CTreeToolBtn(eAddNewPartitionBtn, pBtnItem);
SetItemIcon(pBtnItem, 1);
}
}
}
}
CTreeToolBtn是从QPushButton继承而来
CTreeToolBtn::CTreeToolBtn(EToolBtnType ToolType, QTreeWidgetItem* pSelfItem)
:m_BtnType(ToolType),m_pSelfIterm(pSelfItem)
{
Init(ToolType);
pSelfItem->treeWidget()->setItemWidget(pSelfItem, 0, this);
}
现在问题是Qt程序退出时,会崩溃,如果把CTreeToolBtn::m_pSelfIterm去掉就不会崩溃(这个成员在CTreeToolBtn中除了构造时用于setItemWidget之后都没使用),是为什么呢? 没金币 第一次问 拜托大家了,谢谢
图片说明

  • 点赞
  • 回答
  • 收藏
  • 复制链接分享

1条回答

为你推荐

换一换