当前位置:网站首页>【Qt5】Qt QWidget立刻出现并消失
【Qt5】Qt QWidget立刻出现并消失
2022-07-06 03:26:00 【qq_43478653】
解决方案:
- 如果采用栈上生成对象的方式,即
QWidget w。函数执行完后对象自动销毁,自然也就没有了。除非在父函数内生成或作为类成员记录,以让子函数结束后对象不自动销毁。 - 如果采用堆内存分配对象的方式,即
QWidget* w = new QWidget。函数执行完后对象不会自动销毁,在不设置widget的parent的情况下(设置后widget不会单独出现),应该是不会消失的,但要小心内存泄露的问题。注意,这里采用智能指针如sharedptr还是不可以,因为函数体结束后,智能指针对象销毁,伴随着堆上分配的对象的同时销毁,可以采用方法1的方式进行解决。
边栏推荐
猜你喜欢

Map sorts according to the key value (ascending plus descending)

Pytorch load data

Princeton University, Peking University & UIUC | offline reinforcement learning with realizability and single strategy concentration

C language judgment, ternary operation and switch statement usage

真机无法访问虚拟机的靶场,真机无法ping通虚拟机

Overview of OCR character recognition methods

IPv6 comprehensive experiment

Era5 reanalysis data download strategy

EDCircles: A real-time circle detector with a false detection control 翻译

2.1 rtthread pin设备详解
随机推荐
1.16 - check code
[concept] Web basic concept cognition
Buuctf question brushing notes - [geek challenge 2019] easysql 1
Who is the winner of PTA
Yyds dry inventory what is test driven development
How to do function test well
这些不太会
three. JS page background animation liquid JS special effect
Svg drag point crop image JS effect
Edcircles: a real time circle detector with a false detection control translation
【SLAM】lidar-camera外参标定(港大MarsLab)无需二维码标定板
Idea push rejected solution
【概念】Web 基础概念认知
银行核心业务系统性能测试方法
1、工程新建
js凡客banner轮播图js特效
Résumé des méthodes de reconnaissance des caractères ocr
Leetcode problem solving -- 108 Convert an ordered array into a binary search tree
[Li Kou] the second set of the 280 Li Kou weekly match
ArabellaCPC 2019(补题)