I get this error in my smtdplugin implementation file , when i try to return value. OK so i understand that i’m creating a pointer to an QAction , and when i try to return it , i can not do that because my method is waiting a reference to an object. But i dont know how to act (i’m a begginer)
How to avoid this issue ? , and with success to return that object
#include "smtdplugin.h"
QAction SmtdPlugin::newItem() {
QAction *item = new QAction(NULL);
return item; // here i get error
}
Q_EXPORT_PLUGIN2(smtdplugin,SmtdPlugin);
Header file :
#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
Interface class :
#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
When you do
return item, you are returning a pointer toQAction, but according to the function’s declaration you return aQAction, hence the error.So, you should do: