当创建从qt中的qgraphicspixmapitem创建类中时,尝试引用已删除的函数错误
attempting to reference a deleted function error when create a class inheriting from QGraphicsPixmapItem in QT
我想在我的场景中插入图片,并在检测到图片位置更改时做某事。为了实现这一点,我创建了一个从qgraphicspixmapitem继承的类背景pic。但是,它出现了C2280错误:" BackgroundPic :: BackgroundPic(const BackgroundPic&)':尝试在我尝试编译时尝试引用已删除的函数(编译源文件mainwindow.cpp)。有人知道我的代码中有什么问题?
#include <qstring.h>
#include <qgraphicsproxywidget.h>
class BackgroundPic: public QGraphicsPixmapItem
{
public:
BackgroundPic()
{
show_flag = true;
moveable_flag = true;
}
//QString name;
float x_original; //physical
float y_original;
float x; //physical
float y;
QString pic_address;
bool show_flag;
bool moveable_flag;
QVariant itemChange(GraphicsItemChange change, const QVariant &value)
{
if (change == ItemPositionChange)
{
x = x_original + value.toPointF().x();
y = y_original + value.toPointF().y();
}
return QGraphicsItem::itemChange(change, value);
}
};
问题似乎很清楚,并且在您发布的代码中都不是。在文件mainwindow.cpp中,您可以调用复制构造函数(this BackgroundPic :: backgroundPic(const BackgroundPic&amp;)),但是此函数不可用。
普通复制构造函数是自动定义的(您可以阅读有关零规则和五个规则的规则),但是在您的情况下,这不是。之所以发生,是因为您从没有复制构造函数的类中继承。这意味着您的班级也不可复制。
相关文章:
- 创建引用向量的优雅方式
- 为什么当我们有常量引用时创建临时对象?
- 在函数内创建的对象的范围 - 如果在函数外部存储和访问引用,它们是否有效?
- 如何从绝对地址的 C 样式指针创建对C++对象的引用
- 如何创建对smart_pointer的引用?
- CMake 引用我在 ~/bin 中创建的随机 shell 脚本(即使我删除了它)?
- C++在函数中创建的对 Eigen::Matrix 的悬空引用
- 如何在C++中使用 new 运算符创建对动态创建的数组的引用?
- 从引用创建指向基类的智能指针
- 通过向构造函数其他对象引用页面来创建对象
- C++为具有引用成员变量的类创建复制构造函数
- 创建<int>对整数数组指针的矢量引用 (C++)
- 哪个 const 与哪个引用将更改参数并创建一个 const 对象?
- 将非左值作为常量引用参数传递.临时是在本地作用域还是在调用方作用域中创建的?
- 为什么从引用创建共享指针会复制对象?
- 您可以使用BOOST_AUTO创建引用类型吗?
- c++在函数内部创建引用变量
- 从多个临时文件中创建引用
- 在两个语句中创建引用变量
- 创建引用和创建对象的主要区别是什么?