我尝试连接一个QGraphicsObject子类和一个QGraphicsView子类(在QGraphicsObject构造函数中使用以下行)
connect(this, SIGNAL(paintImage(QPainter *, const QImage &)), this->scene()->views().front(), SLOT(paintImage(QPainter *, const QImage &)));
Run Code Online (Sandbox Code Playgroud)
但是我收到以下错误:
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.
Run Code Online (Sandbox Code Playgroud)
我从QGraphicsView继承自的文档中看到QObject,并且Q_OBJECT两个子类声明中都有宏...有人有想法吗?
QGraphicsView在connect()调用中使用的点是不完整的类型。编译器不知道它继承自QObject,这就是为什么它会报告
无法将'
QGraphicsView *' 转换为'const QObject *'
解决方案是#include <QGraphicsView>在实现文件中connect()调用之前的某个位置。