Results 1 to 5 of 5

Thread: Issue with List of objects made of QObject

  1. #1
    Join Date
    Jan 2012
    Location
    Iran, Tehran
    Posts
    308
    Thanks
    75
    Thanked 24 Times in 21 Posts
    Qt products
    Qt4 Qt5 PyQt3 PyQt4
    Platforms
    Unix/X11 Windows

    Default Issue with List of objects made of QObject

    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?

  2. #2
    Join Date
    Mar 2011
    Location
    Hyderabad, India
    Posts
    1,882
    Thanks
    3
    Thanked 452 Times in 435 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows
    Wiki edits
    15

    Default Re: Issue with List of objects made of QObject

    First thing you have to use QList if pointer to QObject. i.e. QList<QObject *> or simply use QObjectList.

    If i define myObject as pointers then i can’t copy the list because they have defined as pointer
    Why you not able to copy the list? You can copy the QObjectList even though it has pointers.
    When you know how to do it then you may do it wrong.
    When you don't know how to do it then it is not that you may do it wrong but you may not do it right.

  3. #3
    Join Date
    Jan 2012
    Location
    Iran, Tehran
    Posts
    308
    Thanks
    75
    Thanked 24 Times in 21 Posts
    Qt products
    Qt4 Qt5 PyQt3 PyQt4
    Platforms
    Unix/X11 Windows

    Default Re: Issue with List of objects made of QObject

    becuase if i copy it, it will copy the pointers not the values. isn't it right?

  4. #4
    Join Date
    Feb 2011
    Location
    Bangalore
    Posts
    207
    Thanks
    20
    Thanked 28 Times in 27 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Issue with List of objects made of QObject

    No, you cannot go there. The best you can do is to externalize your QObject class internals into another class. A memento design pattern like object and pass those around in the list. Since QObject cannot be copied, there is no other way.

  5. The following user says thank you to pkj for this useful post:

    alizadeh91 (3rd June 2013)

  6. #5
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Issue with List of objects made of QObject

    Quote Originally Posted by alizadeh91 View Post
    becuase if i copy it, it will copy the pointers not the values. isn't it right?
    Yes, it is correct. And what's wrong with that?
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


Similar Threads

  1. QtScript and creating non QObject based objects
    By tbscope in forum Qt Programming
    Replies: 1
    Last Post: 5th October 2011, 08:20
  2. Replies: 0
    Last Post: 12th September 2011, 14:18
  3. Inheritance confusion - which class made inheritating from QObject
    By kornicameister in forum Qt Programming
    Replies: 1
    Last Post: 23rd December 2010, 09:54
  4. Replies: 0
    Last Post: 4th April 2009, 15:54
  5. Replies: 2
    Last Post: 6th December 2006, 23:41

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.