Results 1 to 3 of 3

Thread: Copy an Object

  1. #1
    Join Date
    Apr 2011
    Posts
    195
    Thanks
    49
    Thanked 4 Times in 4 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Copy an Object

    Hi
    I develop a programm where the user is able to build a sql query. A query can consist of several selections. A Selection consists of several conditions.
    Now I want to develop copy and paste function. The user should be able to copy and paste a selection.

    Now my question:
    whats the common way to copy an object (in my case i want to copy the conditions).
    the copied objects should be on a different place on the heap.

    Should I implement a copy-method? Or a copyclass which creates new Objects?

    thank u for help

  2. #2
    Join Date
    Sep 2009
    Location
    Wroclaw, Poland
    Posts
    1,394
    Thanked 342 Times in 324 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: Copy an Object

    If it's a value based class, then you can implement operator = and copy constructor, it will be sensible to copy the objects this way.
    the copied objects should be on a different place on the heap.
    In that case you can provide a "copy" or "clone" method for your class, returning new object with the same properties as copied object.

  3. The following user says thank you to stampede for this useful post:

    Qiieha (11th July 2011)

  4. #3
    Join Date
    Apr 2011
    Posts
    195
    Thanks
    49
    Thanked 4 Times in 4 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Copy an Object

    i know it's a bit late, but i was on holiday = )

    thank u for your reply. I have a lot of objects, so i'll implement a clone method. I think it's the better way, isn't it ?

Similar Threads

  1. Replies: 2
    Last Post: 6th May 2011, 06:56
  2. Replies: 4
    Last Post: 20th August 2010, 13:07
  3. Replies: 1
    Last Post: 30th July 2010, 23:05
  4. writing object to the file(Object Persistance)
    By jjbabu in forum Qt Programming
    Replies: 2
    Last Post: 11th June 2009, 14:28
  5. Open a QMainWindow Object in QDialog Object
    By chuengchuenghq in forum Qt Programming
    Replies: 1
    Last Post: 13th June 2008, 06:33

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.