Krapow
Krapow

Reputation: 641

Qt Connection conversion fail

I try to connect a QGraphicsObject subclass and a QGraphicsView subclass (with the following line in the QGraphicsObject constructor)

connect(this, SIGNAL(paintImage(QPainter *, const QImage &)), this->scene()->views().front(), SLOT(paintImage(QPainter *, const QImage &)));

But I get the following error:

D:\Project\Scene\PointField.cpp:18: error : C2664: 'QMetaObject::Connection QObject::connect(const QObject *,const char *,const char *,Qt::ConnectionType) const: cannot convert 'QGraphicsView *' to 'const QObject *'
The point types are unrelated; conversion needs reinterpret_cast, C style cast or function style cast.

I see from the documentation that QGraphicsView inherits from QObject, and there is the Q_OBJECT macro in both subclass declaration... Does someone have an idea?

Upvotes: 2

Views: 1148

Answers (2)

Toby Speight
Toby Speight

Reputation: 30834

QGraphicsView is an incomplete type at the point where it is used in the connect() call. The compiler doesn't know that it inherits from QObject, and this is why it reports

cannot convert 'QGraphicsView *' to 'const QObject *'

The solution is to #include <QGraphicsView> in the implementation file, somewhere before the connect() call.

Upvotes: 6

Krapow
Krapow

Reputation: 641

I solved my problem by including my QGraphicsView sublass header at the top of the QGraphicsObject subclass header, then clean / execute qmake / rebuild.

Upvotes: 0

Related Questions