Results 1 to 2 of 2

Thread: Regarding the implementation of QList

  1. #1
    Join Date
    Sep 2009
    Posts
    1
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Regarding the implementation of QList

    Hi All,

    I want to implement two QList with the following property:

    1. QList A - List of a specific classes say C1.
    2. QList B - List of pointer from the member of QList A of type C1 so that we can change members of QList A by calling QList B.

    In the QList, i am not able to locate any function that return pointer of the QList member.

    Any idea how can we implement it.

    regards,
    Rachit Gupta

  2. #2
    Join Date
    Sep 2009
    Posts
    140
    Thanks
    4
    Thanked 17 Times in 17 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Regarding the implementation of QList

    I dont think it is a good idea to handle adresses of objects inside a container, since inserting method and algorithm may invalidate them. Even if it would work with a list, it not a good reflex.

    If you want to share data, you can use shared pointers.
    For instance, using STL and boost :
    Qt Code:
    1. //type definition
    2. class C1{};
    3. typedef boost::shared_ptr<C1> C1ShPtr;
    4.  
    5. //list declaration
    6. std::list<C1ShPtr> A, B;
    7.  
    8. //creating and sharing a item in the 2 lists
    9. C1ShPtr item(new C1);
    10. A.push_back(item);
    11. B.push_back(item);
    To copy to clipboard, switch view to plain text mode 

    I let you convert this code with Qt containers to make this post to come back in Qt-related scope

Similar Threads

  1. Sorting using qSort(), - if QList contains POINTERS
    By joseph in forum Qt Programming
    Replies: 13
    Last Post: 18th August 2013, 18:55
  2. QList, copy problems
    By Valheru in forum Qt Programming
    Replies: 4
    Last Post: 5th February 2010, 00:06
  3. QList inside a QList
    By jano_alex_es in forum Newbie
    Replies: 2
    Last Post: 1st July 2009, 11:59
  4. Q3Ptrlist v/s QList
    By joseph in forum Qt Programming
    Replies: 3
    Last Post: 25th September 2007, 11:27
  5. Accessing QList Objects
    By magikalpnoi in forum Qt Programming
    Replies: 7
    Last Post: 21st September 2006, 20:43

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.