QVariant空值不应该被忽略

时间:2013-01-15 10:15:15

标签: c++ qt qt5

我无法理解QVariant对Q_OBJECT子类的行为(GVPalette *继承自具有Q_OBJECT宏的BasicItemNode)。编译器错误是

/qobject.h:471:   instantiated from ‘T qobject_cast(QObject*) [with T = GVPalette*]’
/qvariant.h:584:  instantiated from ‘static T QtPrivate::QVariantValueHelper<T>::object(const QVariant&) [with T = GVPalette*]’
/qvariant.h:100:  instantiated from ‘static ReturnType QtPrivate::ObjectInvoker<Derived, Argument, ReturnType>::invok
                  e(Argument)  [with Derived = QtPrivate::QVariantValueHelper<GVPalette*>, 
                  Argument = const QVariant&, ReturnType = GVPalette*]’
/qvariant.h:593:   instantiated from ‘T qvariant_cast(const QVariant&) [with T = GVPalette*]’
/CLSMetaType.cpp:50:   instantiated from here
/BasicItemNode.h:27: error: void value not ignored as it ought to be

下面的代码片段中的第2行对应于CLSMetaType.cpp:50和第6行。对应于BasicItemNode.h:27

CLSMetaType.cpp
if(variant.canConvert<GVPalette*>()) {
  1.//retVal = variant.value<GVPalette*>()->objectName();
  2. GVPalette* gv = variant.value<GVPalette*>();
  3. retVal = gv->objectName();
}

BasicItemNode.h
4. class BasicItemNode : public QObject
5. {
6.   Q_OBJECT

Qt5- Opensource版本 g ++ - 4.6.3

0 个答案:

没有答案