C++ (Qt)# define Q_DECLARE_INTERFACE(IFace, IId) \ template <> inline const char *qobject_interface_iid<IFace *>() \ { return IId; } \ template <> inline IFace *qobject_cast<IFace *>(QObject *object) \ { return reinterpret_cast<IFace *>((object ? object->qt_metacast(IId) : 0)); } \ template <> inline IFace *qobject_cast<IFace *>(const QObject *object) \ { return reinterpret_cast<IFace *>((object ? const_cast<QObject *>(object)->qt_metacast(IId) : 0)); }
C++ (Qt)template <class T>inline T qobject_cast(QObject *object){#if !defined(QT_NO_QOBJECT_CHECK) reinterpret_cast<T>(object)->qt_check_for_QOBJECT_macro(*reinterpret_cast<T>(object));#endif return static_cast<T>(reinterpret_cast<T>(object)->staticMetaObject.cast(object));} template <class T>inline T qobject_cast(const QObject *object){#if !defined(QT_NO_QOBJECT_CHECK) reinterpret_cast<T>(object)->qt_check_for_QOBJECT_macro(*reinterpret_cast<T>(const_cast<QObject *>(object)));#endif return static_cast<T>(reinterpret_cast<T>(object)->staticMetaObject.cast(object));} template <class T> inline const char * qobject_interface_iid(){ return 0; }
C++ (Qt)template <class T> inline const char * qobject_interface_iid(){ return 0; }
C++ (Qt)#ifndef TESTINTERFACE_H#define TESTINTERFACE_H #include <QObject> class QString;class QStringList; class TestInterface : QObject{ Q_OBJECTpublic: virtual ~TestInterface() {} virtual QStringList operations() const = 0; virtual QString operation(const QString& strOperation ) = 0;signals: void operationSelected(QString oper);}; Q_DECLARE_INTERFACE(TestInterface, "ru.prog.PluginTest.TestInterface/1.1") #endif // TESTINTERFACE_H
C++ (Qt)#ifndef FRUITS_H#define FRUITS_H #include <QtCore>#include "fruits_global.h"#include "../TestInterface.h" class FRUITSSHARED_EXPORT Fruits : public QObject, public TestInterface { Q_OBJECT Q_INTERFACES(TestInterface) public: explicit Fruits(QObject *parent = 0); virtual ~Fruits(); QStringList operations() const; QString operation(const QString &strOperation); signals: void operationSelected(QString oper);}; #endif // FRUITS_H
C++ (Qt)#include "fruits.h"#include <QDebug> Fruits::Fruits(QObject *parent) : QObject(parent){} Fruits::~Fruits(){ } QStringList Fruits::operations() const{ return QStringList() << "apple" << "grape" << "banana" << "kiwi";} QString Fruits::operation(const QString &strOperation){ emit operationSelected(strOperation); if (strOperation == "apple") {return QString("i'm a Apple");} else if (strOperation == "grape") {return QString("i'm a Grape");} else if (strOperation == "banana") {return QString("i'm a Banana");} else if (strOperation == "kiwi") {return QString("i'm a Kiwi");} else {qDebug() << "unsupported operation"; return QString();}} Q_EXPORT_PLUGIN2(TestInterface, Fruits)