Possible Duplicate:
What leads to incomplete types? (QGraphicsItem: Source or target has incomplete type)可能的重复:导致不完整类型的原因是什么?(QGraphicsItem:源或目标类型不完整)
I started out with this question: What leads to incomplete types? (QGraphicsItem: Source or target has incomplete type)
我从这个问题开始:什么导致不完整类型?(QGraphicsItem:源或目标类型不完整)
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.
C664:参数1从'Qt::CursorShape'转换为'const QCursor &'不可能。源或目标具有不完整的类型。
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).
它不会编译,会产生上面提到的错误。但是,在主方法中设置游标,项目为:>setCursor(Qt::OpenHandCursor);工作得很好。错误似乎在其他qgraphicsitem中是持久的(至少我测试了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
谢谢你,露易丝
2 个解决方案
#1
5
On your cpp, include the following line:
在你的cpp中,包括以下一行:
#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.
问题是您正在使用的某些类forward声明QCursor(做了一个forward声明,它是……)呃,说“向前宣告”对吗?OpenHandCursor有这种类型,但是编译器不知道QCursor类是在哪里定义的。在cpp中包含定义所在的文件就可以了。
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.
它在主函数中工作的原因可能是您包含了
#2
0
QGraphicsItems::setCursor expects a reference to an object of type QCursor, but you try to pass Qt::OpenHandCursor which is an enum element, i.e., a constant number which you can use to construct a specific QCursor instance.
setCursor需要一个对QCursor类型的对象的引用,但是要传递Qt::OpenHandCursor,它是enum元素,也就是。,一个常量,您可以使用它来构造一个特定的QCursor实例。
I assume
我认为
setCursor(QCursor(Qt::OpenHandCursor));
will do what you want.
做你想做的。
It would be interesting to know how your "item" is declared which you mentioned as working.
如果您知道您提到的“项目”是如何工作的,那将是很有趣的。
#1
5
On your cpp, include the following line:
在你的cpp中,包括以下一行:
#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.
问题是您正在使用的某些类forward声明QCursor(做了一个forward声明,它是……)呃,说“向前宣告”对吗?OpenHandCursor有这种类型,但是编译器不知道QCursor类是在哪里定义的。在cpp中包含定义所在的文件就可以了。
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.
它在主函数中工作的原因可能是您包含了
#2
0
QGraphicsItems::setCursor expects a reference to an object of type QCursor, but you try to pass Qt::OpenHandCursor which is an enum element, i.e., a constant number which you can use to construct a specific QCursor instance.
setCursor需要一个对QCursor类型的对象的引用,但是要传递Qt::OpenHandCursor,它是enum元素,也就是。,一个常量,您可以使用它来构造一个特定的QCursor实例。
I assume
我认为
setCursor(QCursor(Qt::OpenHandCursor));
will do what you want.
做你想做的。
It would be interesting to know how your "item" is declared which you mentioned as working.
如果您知道您提到的“项目”是如何工作的,那将是很有趣的。