什么导致不完全类型? (QGraphicsItem:源或目标有不完全类型)

编程入门 行业动态 更新时间:2024-10-23 12:34:37
本文介绍了什么导致不完全类型? (QGraphicsItem:源或目标有不完全类型)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我有一个自定义的QGraphicsItem,(除其他外),点击后,使用Qt文档中描述的标准过程将光标更改为开放的手。这工作正常在过去两个星期左右。 昨天,我改变了类中的一些东西。最重要的是,我现在直接从QGraphicsPixmapItem子类,而不是QGraphicsItem。

I have a custom QGraphicsItem, that (among other things) changed the cursor to an open hand when clicked, using the standard procedure as described in the Qt documentation. This worked fine for the past two weeks or so. Yesterday, I changed a few things inside the class. Most significantly, I now subclass directly from QGraphicsPixmapItem instead of QGraphicsItem.

在某些时候,我开始收到以下错误(部分是我自己的翻译):

At some point I started to get the following error (partly my own translation):

C664:参数1从'Qt :: CursorShape'转换为'const QCursor&'不可能。源或目标具有不完整的类型。

C664: Conversion of parameter 1 from 'Qt::CursorShape' to 'const QCursor &' not possible. Source or target has incomplete type.

我现在尝试弄清楚为什么我的项目有一个不完整的类型。不幸的是,我不能回溯这个问题何时开始发生。改变的基类是我唯一的猜测,但我真的不能想到一个如何这可能是原因的方式。在googling错误后,我发现了一些例子,类的成员有些不清楚,但我在我的声明中找不到错误。所以,这里是标题,如果我错过了一些东西:

I now try to figure out why my item has an incomplete type. Unfortunately I can't retrace when exactly this problem started to occur. The changed base class was my only guess, but I could not really think of a way how this could be the cause. After googling the error, I found examples, where members of the class were somewhat ill-defined, but I could not find an error in my declarations. So, here is the Header, in case I missed something:

#include <QGraphicsPixmapItem> class Collection; class ItemSource; class PhotoItem : public QGraphicsPixmapItem { public: PhotoItem( QString sourceFilePath, Collection *collection =0, QColor color =Qt::white, qreal size = 80.0); enum Orientation { portrait, landscape }; QPixmap content(); bool hasContent(); QColor color(); void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget); QRectF boundingRect() const; void mousePressEvent(QGraphicsSceneMouseEvent *event); void mouseMoveEvent(QGraphicsSceneMouseEvent *event); void mouseReleaseEvent(QGraphicsSceneMouseEvent *event); void mouseDoubleClickEvent(QGraphicsSceneMouseEvent *event); private: qreal _size; Orientation _orientation; QPixmap _content; QColor _color; Collection *_collection; ItemSource *_source; };

如果此文件是正确的,那么是否有任何常见问题导致未定义的类型,出来?

If this file is correct, then are there any common problems that lead to undefined types that I can check out? Maybe I am even searching at the wrong place?

感谢您抽出时间, Louise

Thanks for your time, Louise

推荐答案

是什么导致不完整的类型?

What leads to incomplete types?

当不包括定义类型的头文件时,您添加以下行:

When instead of including the header file which defines a type, you add the line:

class myclass;

它转发声明类myclass,这意味着对于编译器它是不完整类型。使用不完整的类型,不能创建它的对象或做任何需要编译器知道myclass的布局,而不是myclass只是一个类型的事实。即:编译器不知道它的成员是什么,它的内存布局是什么。 但是因为指向所有对象的指针只需要相同的内存分配,所以当只是作为指针转换为不完整类型时,可以使用forward声明。

It Forward declares the class myclass which means for compiler it is an Incomplete type. With Incomplete types, One cannot create objects of it or do anything which needs the compiler to know the layout of myclass more than the fact that myclass is just an type. i.e: The compiler does not know what are its members and what its memory layout is. But Since pointers to all objects need just the same memory allocation, You can use the forward declaration when just reffering to an Incomplete type as a pointer.

简而言之,你是向前声明一个类,然后执行一些操作,需要编译器知道该类的布局,因为编译器不知道因此错误。

So in short, You are forward declaring a class and then performing some operations which need the compiler to know the layout of that class, Since the compiler doesn't know it hence the error.

更多推荐

什么导致不完全类型? (QGraphicsItem:源或目标有不完全类型)

本文发布于:2023-11-27 08:57:37,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1637389.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:不完全   类型   目标   QGraphicsItem

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!