Qt 连接转换失败
Qt Connection conversion fail
我尝试连接一个QGraphicsObject
子类和一个QGraphicsView
子类(在QGraphicsObject
构造函数中使用以下行)
connect(this, SIGNAL(paintImage(QPainter *, const QImage &)), this->scene()->views().front(), SLOT(paintImage(QPainter *, const QImage &)));
但是我收到以下错误:
D:ProjectScenePointField.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.
我从文档中看到QGraphicsView
继承自QObject
,并且在两个子类声明中都有Q_OBJECT
宏......有人有想法吗?
QGraphicsView
在connect()
调用中使用时是一个不完整的类型。 编译器不知道它继承自QObject
,这就是为什么它报告
无法将"
QGraphicsView *
"转换为"const QObject *
"
解决方案是在connect()
调用之前的某个位置#include <QGraphicsView>
实现文件中。
我通过在 QGraphicsObject 子类头的顶部包含我的 QGraphicsView sublass 标头来解决我的问题,然后清理/执行 qmake/重建。
相关文章:
- 模板参数替换失败,并且未完成隐式转换
- 分配给转换运算符失败-C++
- 将 const 转换为 const char* 无效,我该如何解决?使用 gcc7 时失败
- PyTorch C++将数据转换为张量失败
- 为什么在此示例中从unique_ptr自动向上转换<derived>到unique_ptr<base>失败?
- 使用静态转换,因为动态转换失败.不好的做法?
- 从 std::vector<double> 到 Python 列表的转换失败(提升 python)
- 从长型转换为相同大小的 int 失败
- 使用提升对字符串进行标记化时,将令牌转换为 char* const* 时失败
- 为什么在此代码中隐式转换为常量迭代器失败?
- 错误:静态断言失败:std ::线程参数必须在转换为rvalues后不可行
- 动态强制转换 (dynamic_cast) 在 OSx (XCode ) 上使用 .dylib 时失败
- C++长到字符串的转换失败
- 将HSV转换为RGB在OpenCV中失败
- QByteArray 转换为十六进制失败
- AIX C++ iconv 转换失败
- 匿名结构可提高函数转换在GCC 5.4上失败
- 将C 方法参数转换为模板参数会因编译错误而失败
- 失败的证明转换字符串到枚举类
- 有没有办法将模板的替换失败转换为布尔值(真/假)或标签(标准::true_type/标准::false_type)