奇怪的“不完全型”错误在QGraphicsItem [英] Weird "incomplete type" error in a QGraphicsItem

查看:554
本文介绍了奇怪的“不完全型”错误在QGraphicsItem的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


可能重复:

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


问题:什么导致不完整的类型? (QGraphicsItem:源或目标具有不完全类型)



如上所述,我得到以下错误(部分是我自己的翻译):


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


尝试找出为什么项目可能不完整,仍然显示错误的情况。奇怪的是:绝对是最小的...



标题:

  #include< QGraphicsPixmapItem> 

class PhotoItem:public QGraphicsPixmapItem
{
public:
PhotoItem();
void someMethod();

protected:
};实施:

  

code> #includephotoitem.h

PhotoItem :: PhotoItem():QGraphicsPixmapItem()
{
QPixmap pxm(80,80);
pxm.fill(Qt :: cyan);
setPixmap(pxm);
}

void PhotoItem :: someMethod()
{
setCursor(Qt :: OpenHandCursor);
}

它不编译,给出上面的错误。然而,使用 item-> setCursor(Qt :: OpenHandCursor); 在main方法中设置光标工作正常。错误似乎是在其他QGraphicsItems(至少我测试QGraphicsRectItem)持久。



我完全困惑,不知道,接下来检查什么。上面的代码是否在其他机器/设置上工作?我还可以测试其他什么来获取更多信息?



谢谢,
Louise

解决方案

在您的cpp中,包括以下行:

  #include< QCursor&问题是,你使用的一些类使用forward声明QCursor(做一个向前的声明,它是。 ..呃,是说'forward declares'是正确的吗?  Qt :: OpenHandCursor 有这种类型,但编译器不知道类QCursor的定义。 



在你的main函数中它的工作原因可能是因为你包含了< QtGui> ,或其他一些包含QCursor的标题,而您不知道它。


Possible Duplicate:
What leads to incomplete types? (QGraphicsItem: Source or target has incomplete type)

I started out with this question: What leads to incomplete types? (QGraphicsItem: Source or target has incomplete type)

As mentioned there, I got the following error (partly my own translation):

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

While trying to figure out why the item might be incomplete, I stripped it down to a minimal test case that still shows the error. Weird thing is: it is absolutely minimal...

Header:

#include <QGraphicsPixmapItem>

class PhotoItem : public QGraphicsPixmapItem
{
public:
    PhotoItem();
    void someMethod();

protected:
};

Implementation:

#include "photoitem.h"

PhotoItem::PhotoItem() : QGraphicsPixmapItem()
{
    QPixmap pxm(80, 80);
    pxm.fill(Qt::cyan);
    setPixmap( pxm );
}

void PhotoItem::someMethod()
{
    setCursor(Qt::OpenHandCursor);
}

It does not compile, giving the error as above. However, setting the cursor in the main method with item->setCursor(Qt::OpenHandCursor); works just fine. The error seems to be persistent across other QGraphicsItems (at least I tested QGraphicsRectItem).

I am utterly confused and don't really know, what to check next. Does the code above work on other machines/setups? What else could I test to get more information?

Thanks, Louise

解决方案

On your cpp, include the following line:

#include <QCursor>

The problem is that some class you are using forward declares QCursor (makes a forward declaration, it is... er, is it right to say 'forward declares'?). Qt::OpenHandCursor has this type, but the compiler does not know where the class QCursor is defined. Including on the cpp the file where the definition is made does the trick.

The reason why it works in your main function is probably because there you are including <QtGui>, or some other header that includes QCursor for you without you knowing about it.

这篇关于奇怪的“不完全型”错误在QGraphicsItem的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆