• 5609阅读
  • 8回复

如何重新构造QAction类? [复制链接]

上一主题 下一主题
离线pqfeng
 
只看楼主 倒序阅读 楼主  发表于: 2009-05-12
如何重新构造QAction类?
class MyAction : public QAction
{
public:
    MyAction();
    void *point;
    void setPoint(void *po);
};
MyAction::MyAction()
{
}

MyAction::setPoint(void *po)
{
    point = po;
}

我这样做,然后再申请变量 MyAction *action = new MyAction();
它报D:/My Documents/mdi/myaction.cpp:4: error: no matching function for call to `QAction::QAction()'
离线pqfeng
只看该作者 1楼 发表于: 2009-05-12
救命呀。没人帮我?》
离线hxcan

只看该作者 2楼 发表于: 2009-05-14
是因为你没有#include <QAction>吗?
本座已达到法定娶亲年龄,欲购从速,价格面谈。
杀人容易爱人难。
作为一个太极美术工程师,我深刻地感受到:世风日下、人心不古。
http://StupidBeauty.com/Blog
离线pqfeng
只看该作者 3楼 发表于: 2009-05-14
当然是有包含呀。兄弟。
离线paomu52
只看该作者 4楼 发表于: 2009-05-14
子类的构造函数没有 清楚的写出 基类的构造函数吧!
离线paomu52
只看该作者 5楼 发表于: 2009-05-14
你看看我发的贴 的问题 我现在郁闷

继承后 不能使用基类中的 控件指针 ?

你能否给点意见????
离线songxizg

只看该作者 6楼 发表于: 2009-05-14
构造函数改下试试
MyAction::MyAction(QWidget *parent):QAction(parent)
{

}
离线ttylikl

只看该作者 7楼 发表于: 2009-05-14
这个错误很明显啊,因为父类QAction里没有QAction()这样一个默认构造函数,而你在子类的构造函数里又没有使用基类的其他构造函数,当然会报错了。你看一下QAction的构造函数:
QAction ( QObject * parent )
QAction ( const QString & text, QObject * parent )
QAction ( const QIcon & icon, const QString & text, QObject * parent )

然后在MyAction构造函数里去调用吧。比如象 6 楼的哥们举的例子。
离线txflhl

只看该作者 8楼 发表于: 2009-05-26
class ction : public QAction
{
    Q_OBJECT

public:
    ction(QAction* parent = 0);
//protected:
//   void mousePressEvent(QGraphicsSceneMouseEvent *mouseEvent);
};

ction::ction( QAction *parent)
        :QAction(parent)
{

}

问题解决。由于QAction本事的构造函数的的关系造成的。
快速回复
限100 字节
 
上一个 下一个