Hello all. I want to store smart pointers in QVariants for purposes of working with Qt's model/view system. However, it appears that QVariant.operator== doesn't work when the type is a smart pointer. For example:
Qt Code:
#include <boost/shared_ptr.hpp> Q_DECLARE_METATYPE(boost::shared_ptr<int>); Q_DECLARE_METATYPE(int*); void testQVariant() { int* rawInt = new int(5); bool equal = rawVariant2 == rawVariant; boost::shared_ptr<int> smartInt(new int(5)); equal = smartVariant2 == smartVariant; }To copy to clipboard, switch view to plain text mode
The QVariants are equal when using raw pointers, but not when using smart pointers (boost::shared_ptr in this case, but I see the same behavior with another smart pointer type, as well).
The upshot is that I can store these in a model (as Qt::UserRole data), but I'm unable to ask the model to find them (match() always returns an index of -1). Any ideas?
Bookmarks