• Skip to content
  • Skip to link menu
KDE 4.2 API Reference
  • KDE API Reference
  • kdelibs
  • Sitemap
  • Contact Us
 

Kross

Kross::WrapperInterface

Kross::WrapperInterface Class Reference

Wrapper-class used to provide handlers for custom types. More...

#include <wrapperinterface.h>

List of all members.


Public Member Functions

virtual void * wrappedObject () const =0
virtual ~WrapperInterface ()

Detailed Description

Wrapper-class used to provide handlers for custom types.

Custom types are types other than QObject*, QWidget* or one of the base types supported by QVariant. By using the Kross::registerMetaTypeHandler() method such custom handlers can be registered and used to either translate various types to a by QVariant supported type or by providing on the fly an own wrapper class that inherits from QObject and does provide access to the functionality of the wrapped custom type.

Following sample demonstrates the usage by registering a handler for the type "TestObject*". Once such a type got returned by a C++ class, the handler got called. If we return a QObject that implements the WrapperInterface, what is not needed, then the wrappedObject() method will be used to translate the wrapper back to the wrapped object if a C++ function got called and the wrapper is passed as argument.

 // This is our wrapper class we are using to e.g. provide
 // additional functionality on the fly or to provide access
 // to a C++ type that does not inherit from QObject.
 class MyWrapper : public QObject, public Kross::WrapperInterface {
     public:
         MyWrapper(QObject* obj) : QObject(obj) {}
         void* wrappedObject() const { return parent(); }
 };
 // This function will be called by Kross if a type named
 // "TestObject*" got returned by a C++ method.
 QVariant TestObjectHandler(void* ptr)
 {
     TestObject* obj = static_cast<TestObject*>(ptr);
     MyWrapper* w = new MyWrapper(obj);
     QVariant r;
     r.setValue( (QObject*)w );
     return r;
 }
 // and somewhere else we finally register our function.
 Kross::Manager::self().registerMetaTypeHandler("TestObject*", TestObjectHandler);

Since:
4.2

Definition at line 73 of file wrapperinterface.h.


Constructor & Destructor Documentation

WrapperInterface::~WrapperInterface (  )  [virtual]

Destructor.

Definition at line 512 of file action.cpp.


Member Function Documentation

virtual void* Kross::WrapperInterface::wrappedObject (  )  const [pure virtual]

This method got called by Kross if the wrapper-instance got passed to a C++ slot.

It is recommed to return here the wrapped instance, but you don't need to.


The documentation for this class was generated from the following files:
  • wrapperinterface.h
  • action.cpp

Kross

Skip menu "Kross"
  • Main Page
  • Namespace List
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Namespace Members
  • Class Members
  • Related Pages

kdelibs

Skip menu "kdelibs"
  • DNSSD
  • Interfaces
  •   KHexEdit
  •   KMediaPlayer
  •   KSpeech
  •   KTextEditor
  • Kate
  • kconf_update
  • KDE3Support
  •   KUnitTest
  • KDECore
  • KDED
  • KDEsu
  • KDEUI
  • KDocTools
  • KFile
  • KHTML
  • KImgIO
  • KInit
  • kio
  • KIOSlave
  • KJS
  •   KJS-API
  •   WTF
  • kjsembed
  • KNewStuff
  • KParts
  • Kross
  • KUtils
  • Nepomuk
  • Plasma
  • Solid
  • Sonnet
  • ThreadWeaver
Generated for kdelibs by doxygen 1.5.7
This website is maintained by Adriaan de Groot and Allen Winter.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal