我有这样一个类层次结构:
class Base {
...
virtual QWidget* getEditor();
...
}
class Derived {
...
QWidget* getEditor() Q_DECL_OVERRIDE;
...
}
这两个类都是通过 Q_DECLARE_METATYPE() 注册的
我从 QVariant 获取 Base 类的实例。是否可以从 QVariant 获取指针以便能够getEditor()
从 Derived 对象调用?
我正在尝试这个 atm 但没有成功:
if (index.data(Qt::EditRole).canConvert<Base>())
return index.data(Qt::EditRole).value<Base>().getEditor(parent);
这个 snipper 调用 Base 类方法。