查看完整版本: [-- QList<结构体> vList如何清空 --]

QTCN开发网 -> Qt基础编程 -> QList<结构体> vList如何清空 [打印本页] 登录 -> 注册 -> 回复主题 -> 发表主题

lwei24 2022-11-29 19:57

QList<结构体> vList如何清空

如题,QList<结构体> vList如何清空?用foreach逐个清空?各位大佬,有没有试过清空QList<结构体> vList呢?


clickto 2022-11-29 20:16
清空是指?
如果只是清除元素,直接clear即可,如果需要释放内存,自行循环释放吧,容器不管元素的内存释放

lwei24 2022-12-09 13:51
clickto:清空是指?
如果只是清除元素,直接clear即可,如果需要释放内存,自行循环释放吧,容器不管元素的内存释放 (2022-11-29 20:16) 

好吧,多谢!

lzh280 2022-12-12 15:16
qDeleteAll:
QList<Employee *> list;
list.append(new Employee("Blackpool", "Stephen"));
list.append(new Employee("Twist", "Oliver"));

qDeleteAll(list.begin(), list.end());
list.clear();

lwei24 2022-12-13 18:44
lzh280:qDeleteAll:
QList<Employee *> list;
list.append(new Employee("Blackpool", "Stephen"));
list.append(new Employee("Twist", "Oliver"));
....... (2022-12-12 15:16) 

QList<结构体>,这个结构体不是指针,指针的话,倒是很容易清空!


查看完整版本: [-- QList<结构体> vList如何清空 --] [-- top --]



Powered by phpwind v8.7 Code ©2003-2011 phpwind
Gzip disabled