Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Issue with QList and Copy QList with objects made of QObject

Issue with QList and Copy QList with objects made of QObject

Scheduled Pinned Locked Moved General and Desktop
6 Posts 3 Posters 2.2k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    alizadeh91
    wrote on last edited by
    #1

    Hi,
    I have list of objects(made of QObject - myList<myObject>).
    For some reasons user may be want to modify this list or maybe he/she want to cancel the modifications.
    The solution which has came into my mind is to make a copy of my list and give it to user while keeping original one.
    so whenever user modify copied list, i have original list so i can change it or revert it based on what user wants.
    But the problem is that the objects are made of QObject, so they can not be copied(Copy constructor and
    assignment have disabled in qobject)!!! I don't know what else to do?!
    If i define myObject as pointers then i can't copy the list because they have defined as pointer
    Thanks if someone can help me through this. or may be i can use another approach?

    1 Reply Last reply
    0
    • B Offline
      B Offline
      bodzio131
      wrote on last edited by
      #2

      Hi,
      Do you want to modify list of your objects? or your objects in your list?
      If the first then I think the copy is not needed at all, you can store pointers and move them somewhere if necessary.
      If the second then consider "'memento' design pattern":http://sourcemaking.com/design_patterns/memento, it helps to store history of object's states.

      Best regards

      1 Reply Last reply
      0
      • A Offline
        A Offline
        alizadeh91
        wrote on last edited by
        #3

        Thanks for quick reply,
        Both, user can add or remove from list and can edit objects in the list.

        1 Reply Last reply
        0
        • B Offline
          B Offline
          bodzio131
          wrote on last edited by
          #4

          There is also another solution: create 'clone' method which produces exact copy of your object.

          1 Reply Last reply
          0
          • A Offline
            A Offline
            alizadeh91
            wrote on last edited by
            #5

            Thanks, got it :)

            1 Reply Last reply
            0
            • SGaistS Offline
              SGaistS Offline
              SGaist
              Lifetime Qt Champion
              wrote on last edited by
              #6

              Hi,

              One question: Does your class really need to be derived from QObject ?

              Interested in AI ? www.idiap.ch
              Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

              1 Reply Last reply
              0

              • Login

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • Users
              • Groups
              • Search
              • Get Qt Extensions
              • Unsolved