Results 1 to 6 of 6

Thread: Store QWeakPointers in QSet

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    May 2013
    Posts
    24
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Store QWeakPointers in QSet

    Hi,

    I'm trying to store QWeakPointers in a QSet with no success. The compiler first complained about QWeakPointer is lacking a qHash function. I Implemented a qHashFunction, the project compiled but I can't fetch data from the QSet (tried iterators). It only returns invalid QWeakPointers.

    Basically I'm trying to do:
    Qt Code:
    1. QSet<QWeakPointer<MyClass> > oneSet;
    2. QSharedPointer<MyClass> > myClass(new MyClass);
    3. oneSet.insert(oneSet.toWeakRef());
    4.  
    5. for (QSet<QWeakPointer<MyClass> >::iterator it = oneSet.begin(); it != oneSet.end(); it++)
    6. {
    7. // do stuff
    8. }
    9.  
    10.  
    11. //My qHash:
    12. template<typename T>
    13. uint qHash(const QWP<T> &p)
    14. {
    15. return qHash(p.data()); //use the pointer a a key.
    16. }
    To copy to clipboard, switch view to plain text mode 

    Does anyone have a solution for this?
    Last edited by high_flyer; 22nd August 2013 at 16:49. Reason: code tags

Similar Threads

  1. modifying QSet via STL iterator
    By tuli in forum Qt Programming
    Replies: 1
    Last Post: 11th April 2013, 08:34
  2. QSet of QDateTime
    By Cucumber in forum Newbie
    Replies: 2
    Last Post: 21st January 2012, 02:17
  3. Using custom class as a key (QSet)
    By daujeroti in forum Qt Programming
    Replies: 4
    Last Post: 28th April 2011, 20:39
  4. QSet<QVariant> is supported ?
    By nikhilqt in forum Qt Programming
    Replies: 1
    Last Post: 4th February 2010, 07:14
  5. QSet and custom class
    By been_1990 in forum Qt Programming
    Replies: 12
    Last Post: 22nd January 2010, 16:36

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
  •  
Qt is a trademark of The Qt Company.