【发布时间】:2011-11-23 14:28:13
【问题描述】:
当我尝试返回值时,我的 smtdplugin 实现文件中出现此错误。好的,所以我知道我正在创建一个指向 QAction 的指针,当我尝试返回它时,我不能这样做,因为我的方法正在等待对对象的引用。但我不知道如何行动(我是一个初学者) 如何避免这个问题? ,并成功返回该对象
#include "smtdplugin.h"
QAction SmtdPlugin::newItem() {
QAction *item = new QAction(NULL);
return item; // here i get error
}
Q_EXPORT_PLUGIN2(smtdplugin,SmtdPlugin);
头文件:
#ifndef SMTDPLUGIN_H
#define SMTDPLUGIN_H
#include <QObject>
#include <QAction>
#include "smtdinterface.h"
class SmtdPlugin : public QObject,SmtdInterface {
Q_OBJECT
Q_INTERFACES (SmtdInterface)
public :
QAction newItem();
};
#endif // SMTDPLUGIN_H
接口类:
#ifndef SMTDINTERFACE_H
#define SMTDONINTERFACE_H
#include <QAction>
class SmtdInterface {
public:
virtual ~SmtdInterface() {}
SmtdInterface();
virtual QAction newItem () = 0;
};
Q_DECLARE_INTERFACE(SmtdInterface,"com.trololo.Plugin.SmtdInterface/1.0")
#endif
【问题讨论】: