qvariant

How to support comparisons for QVariant objects containing a custom type?

♀尐吖头ヾ 提交于 2019-11-29 09:07:29
According to the Qt documentation, QVariant::operator== does not work as one might expect if the variant contains a custom type: bool QVariant::operator== ( const QVariant & v ) const Compares this QVariant with v and returns true if they are equal; otherwise returns false. In the case of custom types, their equalness operators are not called. Instead the values' addresses are compared. How are you supposed to get this to behave meaningfully for your custom types? In my case, I'm storing an enumerated value in a QVariant, e.g. In a header: enum MyEnum { Foo, Bar }; Q_DECLARE_METATYPE(MyEnum);

How can I cast a QVariant to custom class?

烈酒焚心 提交于 2019-11-29 01:52:42
I'm developing a BlackBerry 10 mobile application using the Momentics IDE (native SDK). I have a listview which I want to handle its items click with C++ (I need to use C++ not QML). I can get the index path using the "connect" instruction, but I have problem with parsing a QVariant to a custom class ; Q_ASSERT(QObject::connect(list1, SIGNAL(triggered(QVariantList)), this, SLOT(openSheet(QVariantList)))); QVariant selectItem = m_categoriesListDataModel->data(indexPath); I tried to use the static cast like below Category* custType = static_cast<Category*>(selectItem); but it returns : "invalid

How to verify QVariant of type QVariant::UserType is expected type?

匆匆过客 提交于 2019-11-28 07:31:20
问题 I'm writing testing code that will automatically iterate thru all Q_PROPERTY's of widgets and some properties are using types that are registered via qRegisterMetaType. If i want to read/write these into QVariant i need to use QVariant::UserType when storing them into variant. So far so good. But when i want to test reads and writes of these properties, i need to also know their type. For stuff that are already standard qt types, i can do this via QVariant::type() but as i have alot of

How to support comparisons for QVariant objects containing a custom type?

时光怂恿深爱的人放手 提交于 2019-11-28 02:28:40
问题 According to the Qt documentation, QVariant::operator== does not work as one might expect if the variant contains a custom type: bool QVariant::operator== ( const QVariant & v ) const Compares this QVariant with v and returns true if they are equal; otherwise returns false. In the case of custom types, their equalness operators are not called. Instead the values' addresses are compared. How are you supposed to get this to behave meaningfully for your custom types? In my case, I'm storing an