How do I copy object in Qt?

后端 未结 3 647
梦毁少年i
梦毁少年i 2020-11-27 21:40

I\'m using Qt and have some real basic problems. I have created my own widget MyTest that have a variable obj. I need to set this variable obj from

3条回答
  •  渐次进展
    2020-11-27 22:27

    Aaron is correct about using the assignment operator.

    The only way that I'm aware of to make a copy of an object, if you really have to, is to use Serialization as described in QDataStream Class. This would make a deep copy of the object.

    Or have you considered wrapping the class as a QSharedPointer pointer that you can safely pass around. This would be a shadow or reference copy of the object though.

提交回复
热议问题