有一个接口类:
class PropertyInface
{
public:
virtual QStringList getPropertys() =0;
}
然后写了个派类:
class Item : public QObject ,public PropertyInface
{
Q_OBJECT
public:
QStringList getPropertys() ;
public:
其它方法
}
在其它的类中有个函数:updateInfo( PropertyInface* prop ) ;
如果调用此函数时:
Item* myitem = new Item();
....
updateInfo(myitem);
则在updateInfo函数内部,在调用getPropertys() 时可能会出错,
如果使用如下调用:
PropertyInface* inf = ......
updateInfo(inf);
则在updateInfo函数内部调用inf.property("objectName")等QObject及Item中的方法时也会出错。
在调试时发现,调用inf->getPropertys()时,实际调用的是Item的其它函数。好像Item的虚函数表发生的混乱,把QObject及PropertyInface的虚函数地址处理错了。
请教各位,这种问题如何解决?>>>>>
接口类PropertyInface实际定义的函数为:
virtual QList<ProperyInfo> getPropertys() =0;
ProperyInfo是我定义的一个类,保存属性信息。为了能在QVariant中使用用了一个宏:
Q_DECLARE_METATYPE( ProperyInfo ) 会不会是这个宏造成的 ?
ProperyInfo定义如下:
class ProperyInfo{
public:
公有方法有变量
public:
ProperyInfo();
ProperyInfo(const ProperyInfo& orig );
ProperyInfo &operator=(const ProperyInfo& orig );
private:
私有的方法及变量
[ 此帖被sanghk在2009-03-03 14:17重新编辑 ]