From 5e02b5defe3e4690723bdcdeeddce8533dcb55cc Mon Sep 17 00:00:00 2001 From: Mathew Sutcliffe Date: Sat, 5 Sep 2015 20:02:52 +0100 Subject: [PATCH] refs #459 Fixed "CVariant requested unsupported operation" errors. --- src/blackmisc/variant_private.h | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/src/blackmisc/variant_private.h b/src/blackmisc/variant_private.h index 2e07b21a3..3ed493112 100644 --- a/src/blackmisc/variant_private.h +++ b/src/blackmisc/variant_private.h @@ -64,7 +64,9 @@ namespace BlackMisc { public: template - CVariantException(const T &, const QString &operationName) : std::invalid_argument((blurb(operationName)).toStdString()), m_operationName(operationName) {} + CVariantException(const T &, const QString &opName) : CVariantException(qMetaTypeId(), opName) {} + + CVariantException(int typeId, const QString &opName) : std::invalid_argument((blurb(typeId, opName)).toStdString()), m_operationName(opName) {} const QString &operationName() const { return m_operationName; } @@ -73,23 +75,28 @@ namespace BlackMisc private: QString m_operationName; - template - static QString blurb(const QString &operationName) + static QString blurb(int typeId, const QString &operationName) { - return QString("CVariant requested unsupported operation of contained ") + QMetaType::typeName(qMetaTypeId()) + " object: " + operationName; + return QString("CVariant requested unsupported operation of contained ") + QMetaType::typeName(typeId) + " object: " + operationName; } }; //! \private namespace Fallback { + //! \private Class with a conversion constructor template from any type. + struct FromAny + { + template + FromAny(const T &) : m_type(qMetaTypeId()) {} + int m_type; + }; + //! \private Fallback in case qHash is not defined for T. - template - uint qHash(const T &object) { throw CVariantException(object, "qHash"); } + inline uint qHash(const FromAny &object) { throw CVariantException(object.m_type, "qHash"); } //! \private Fallback in case compare is not defined for T. - template - int compare(const T &a, const T &) { throw CVariantException(a, "compare"); } + inline int compare(const FromAny &a, const FromAny &) { throw CVariantException(a.m_type, "compare"); } } //! \private Implementation of IValueObjectMetaInfo representing the set of operations supported by T.