我正在尝试创建一个自定义QGraphicsItem按钮,如Fred 这里所示。他发布的代码可以找到这里。
问题是,当我试图编译代码时,会出现以下两个错误:
下面是代码片段,本质上与上面的示例中的代码片段相同。错误发生在类减速上。
class MyButton : public QObject, public QGraphicsItem
{
Q_OBJECT
Q_INTERFACES(QGraphicsItem)
public:
MyButton(QGraphicsItem *parent = 0);
MyButton(const QString normal, const QString pressed = "", QGraphicsItem *parent = 0);
....
}有趣的是,另一个示例如图所示,这里工作得很好。它的示例代码可以找到这里。
知道是怎么回事吗?提前谢谢。
发布于 2010-04-20 22:37:45
这些错误看起来像是试图复制按钮对象。编译器试图自动生成MyButton复制构造函数,但失败了,因为QObject的复制构造函数(即按钮库)是私有的。除了列出的错误之外,您还应该看到如下内容:
note: synthesized method 'MyButton::MyButton(const MyButton&)' first required here在此消息后面有源文件名和行号。如果您没有看到这条消息,请尝试添加:
private:
Q_DISABLE_COPY(MyButton)到MyButton类定义。那你应该看看这个:
error: 'MyButton::MyButton(const MyButton&)' is private within this contexthttps://stackoverflow.com/questions/2678661
复制相似问题