Take the 2-minute tour ×

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...


#include <QGraphicsPixmapItem>

class PhotoItem : public QGraphicsPixmapItem
    void someMethod();



#include "photoitem.h"

PhotoItem::PhotoItem() : QGraphicsPixmapItem()
    QPixmap pxm(80, 80);
    setPixmap( pxm );

void PhotoItem::someMethod()

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

share|improve this question
+1 for creating a simple example where your problem still happens –  Castilho Apr 12 '12 at 11:14
... I already posted the answer to this in your previous question to which you've linked. –  Styne666 Apr 12 '12 at 12:05
yep, and +1 there ;) Thought you could migrate it to here, but Castilho had already answered, and quite specifically. –  Louise Apr 12 '12 at 12:48
add comment

marked as duplicate by casperOne Apr 14 '12 at 12:56


2 Answers

up vote 3 down vote accepted

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.

share|improve this answer
Such a simple, tiny thing... Thanks a lot! I really feel like I should have known - I guess I got really confused because it worked before for a long time. ;) But as you said: I must have included something that included QCursor unknowingly, that got lost when I cleaned up the project. –  Louise Apr 12 '12 at 11:32
add comment

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.

I assume


will do what you want.

It would be interesting to know how your "item" is declared which you mentioned as working.

share|improve this answer
Your thought was actually my first idea, although the line using the enum Qt::CursorShape originates from the Qt examples and definitely worked previously. I tried the same line as you gave, with the same error as before. Then I stumbled across the little note in the compiler message about the incomplete type, which led to the above question and Castilho's answer solves and explains my problem. Qt does some magic behind the curtains so that the enum is transformed into the needed cursor, so you can use it this way. –  Louise Apr 12 '12 at 11:52
add comment
