当前位置:网站首页>【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的方式进行解决。
边栏推荐
- Derivation of anti Park transform and anti Clarke transform formulas for motor control
- 遥感图像超分辨重建综述
- 1.16 - 校验码
- Deep parsing pointer and array written test questions
- Redis SDS principle
- 给新人工程师组员的建议
- JS音乐在线播放插件vsPlayAudio.js
- Teach you to build your own simple BP neural network with pytoch (take iris data set as an example)
- Pointer written test questions ~ approaching Dachang
- The next industry outlet: NFT digital collection, is it an opportunity or a foam?
猜你喜欢
How to do function test well
ASU & OSU | model based regularized off-line meta reinforcement learning
Force buckle 1189 Maximum number of "balloons"
Microsoft Research, UIUC & Google research | antagonistic training actor critic based on offline training reinforcement learning
Tomb. Weekly update of Finance (February 7 - February 13)
SWC introduction
[slam] orb-slam3 parsing - track () (3)
Esbuild & SWC: a new generation of construction tools
Idea push rejected solution
[risc-v] external interrupt
随机推荐
RT-Thread--Lwip之FTP(2)
Pytorch基础——(2)张量(tensor)的数学运算
Audio-AudioRecord Binder通信机制
Pelosi: Congress will soon have legislation against members' stock speculation
下一个行业风口:NFT 数字藏品,是机遇还是泡沫?
[Li Kou] the second set of the 280 Li Kou weekly match
Four logs of MySQL server layer
3.2 rtthread 串口设备(V2)详解
The next industry outlet: NFT digital collection, is it an opportunity or a foam?
Pytorch基础——(1)张量(tensor)的初始化
Shell pass parameters
Redis cache breakdown, cache penetration, cache avalanche
暑期刷题-Day3
继承day01
How to write compile scripts compatible with arm and x86 (Makefile, cmakelists.txt, shell script)
2022工作中遇到的问题四
遥感图像超分辨率论文推荐
Cubemx 移植正点原子LCD显示例程
[rust notes] 18 macro
BUAA喜鹊筑巢