首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 移动开发 > QT开发 >

一个关于qt c++的有关问题

2012-01-24 
一个关于qt c++的问题。今天读QT帮助文档 有这样一段话To write your own graphics item, you first create

一个关于qt c++的问题。
今天读QT帮助文档 有这样一段话
To write your own graphics item, you first create a subclass of QGraphicsItem, and then start by implementing its two pure virtual public functions: boundingRect(), which returns an estimate of the area painted by the item, and paint(), which implements the actual painting. 

1、这段话的意思是要想继承QGraphicsItem必须实现这个类里面的两个纯虚函数。boundingRect()、paint()。
2、c++里有春旭函数的类、或者子类没有覆盖纯虚函数的类为抽象类。 抽象类的一个特性是不能声明对象。(大学里c++教材里说的)。
3、按这种说法,QGRaphicsItem就是抽象类了。 那么QGraphicsItem 就不能声明对象。

但是qt里面 可以 QGraphicsItem *item = new QGraphicsItem(this); 声明一个对象啊。

这是怎么回事呢。QT里面是如何实现的呢? 



[解决办法]
但是qt里面 可以 QGraphicsItem *item = new QGraphicsItem(this); 声明一个对象啊。
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
这样应该会报错的 
error: cannot allocate an object of abstract type 'QGraphicsItem'
[解决办法]
错误:cannot allocate an object of abstract type 'QGraphicsItem'
: because the following virtual functions are pure within 'QGraphicsItem':
: virtual QRectF QGraphicsItem::boundingRect() const
: virtual void QGraphicsItem::paint(QPainter*, const QStyleOptionGraphicsItem*, QWidget*)

如果要是实例化 ,回出现如上的错误,存在纯虚函数;
可以定义其指针对象与引用

热点排行