【问题标题】:Error by creating a list of QGraphicsItems创建 QGraphicsItem 列表时出错
【发布时间】:2011-10-18 01:41:33
【问题描述】:

我有一个 QGraphicsScene,我想在上面画一些特殊的曲线。为此,我创建了一个类,在其中我将这些特殊曲线定义为新的 QGraphicsItem:

#include &lt QGraphicsItem> 类 Clothoid:公共 QGraphicsItem { 民众: Clothoid(QPoint startPoint, QPoint endPoint); 虚拟〜Clothoid(); QPoint 点; QPoint ePoint; 浮动开始曲率; 浮动结束曲率; 浮动回旋线长度; 受保护: QRectF boundingRect() 常量; void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget); };

我尝试将每个项目插入两次:一次在我定义的数组中:

QList 回旋曲线;

在场景中一次:

void renderArea::updateClothoid(const QPoint &p1, const QPoint &p2) { Clothoid *temp = new Clothoid(p1, p2); clothoids.append(&temp); 场景->addItem(&temp); }

但是我得到了这两个错误:

没有匹配函数调用'QList::append(Clothoid**)'

没有匹配函数调用'QGraphicsScene::addItem(Clothoid**)'

我做错了什么?

【问题讨论】:

    标签: qt4 qlist qgraphicsscene


    【解决方案1】:

    应该是:

    clothoids.append(temp);
    scene->addItem(temp);
    

    QList 应该定义为:

    QList<Clothoid*> clothoids;
    

    【讨论】:

    • 这样尝试过,现在 qgraphicsscene 的错误消失了,但 qlist 的错误仍然存​​在。
    • QList 应该包含指向 Clothoid 对象的指针。我已经用代码更新了我的答案。
    猜你喜欢
    • 2015-07-16
    • 1970-01-01
    • 2014-07-24
    • 1970-01-01
    • 2018-10-21
    相关资源
    最近更新 更多