指针管理问题

SilenceSu 2012-10-16 02:08:28

在Run类中new了一个Test
 Test *t=new Test();
t.show();


Test是这样的


void Widget::enterEvent(QEvent *e){
i=1;
}

void Widget::leaveEvent(QEvent *e){
if(i==1){
this->deleteLater();
}
}

就是鼠标移除之后自己删除、

请问这个有木有内存泄露

Run类的t指针还需要销毁吗?
...全文
134 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
  • 打赏
  • 举报
回复
不需要哈。 deletelater其实就是发个delete消息给自己。。。然后自己收到消息了。。就删除自己。。
风为裳のCode 2012-10-16
  • 打赏
  • 举报
回复
Schedules this object for deletion.

The object will be deleted when control returns to the event loop. If the event loop is not running when this function is called (e.g. deleteLater() is called on an object before QCoreApplication::exec()), the object will be deleted once the event loop is started.

Note that entering and leaving a new event loop (e.g., by opening a modal dialog) will not perform the deferred deletion; for the object to be deleted, the control must return to the event loop from which deleteLater() was called.

Note: It is safe to call this function more than once; when the first deferred deletion event is delivered, any pending events for the object are removed from the event queue.

See also destroyed() and QPointer.
SilenceSu 2012-10-16
  • 打赏
  • 举报
回复
完了? 没有人了?
SilenceSu 2012-10-16
  • 打赏
  • 举报
回复
写错....
[Quote=引用 1 楼 的回复:]

你确定是t.show() 而不是t->show()??
[/Quote]
  • 打赏
  • 举报
回复
可以看看Qt助手对deleteLater的解释
风为裳のCode 2012-10-16
  • 打赏
  • 举报
回复
你确定是t.show() 而不是t->show()??

16,204

社区成员

发帖
与我相关
我的任务
社区描述
Qt 是一个跨平台应用程序框架。通过使用 Qt,您可以一次性开发应用程序和用户界面,然后将其部署到多个桌面和嵌入式操作系统,而无需重复编写源代码。
社区管理员
  • Qt
  • 亭台六七座
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧