如何深度复制QMap等Qt容器 [英] How to deep copy QMap and other Qt containers

查看:1857
本文介绍了如何深度复制QMap等Qt容器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

一般来说,深层复制Qt容器的正确方法是什么?我不担心深入复制容器,虽然解决这样的问题是有帮助的。

Generally speaking, what is the correct way to deep copy Qt containers? I'm not worried about deep copying the containers recursively, although addressing such would be helpful.

推荐答案

尽管大家都会告诉你 - 你不深的复制Qt容器 - 有些情况下,你只需要执行一个实际的深复制,而不是只是一个浅的。为此,使用 detach()

Despite what everyone will tell you - that you don't deep copy Qt containers - there are situations in which you simply need to perform an actual deep copy instead of just a shallow one. To do that, use detach():

container1 = container2;
container1.detach();

这篇关于如何深度复制QMap等Qt容器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆