QtMvvm  1.1.0
A mvvm oriented library for Qt, to create Projects for Widgets and Quick in parallel
Namespaces | Macros | Functions
injection.h File Reference

A header with injection related code. More...

#include "qtmvvmcore_global.h"

Go to the source code of this file.

Namespaces

 QtMvvm
 The primary namespace of the QtMvvm library.
 

Macros

#define QTMVVM_INJECT(classType, name)
 Mark a property for injection. More...
 
#define QTMVVM_INJECT_PROP(type, name, member)
 Create a for injection marked property based on a member. More...
 

Functions

template<typename TInterface >
void QtMvvm::registerInterfaceConverter ()
 Registers QVariant converters from QObject to an interface type registered with Q_DECLARE_INTERFACE.
 

Detailed Description

A header with injection related code.

Definition in file injection.h.

Macro Definition Documentation

◆ QTMVVM_INJECT

#define QTMVVM_INJECT (   classType,
  name 
)
Value:
static inline QByteArray __qtmvvm_inject_##name() { \
return QtMvvm::__helpertypes::inject_iid<classType>(); \
} \
Q_PROPERTY(QByteArray __qtmvvm_inject_##name READ __qtmvvm_inject_##name STORED false SCRIPTABLE false DESIGNABLE false CONSTANT FINAL)

Mark a property for injection.

Parameters
classTypeThe type of the property to be injected
nameThe name of the property to be injected

This macro creates an additional property that is detected by the QtMvvm::ServiceRegistry and contains the information needed to inject the property automatically. For more details on the property injection, see QtMvvm::ServiceRegistry

Sample code for usage:

class MyClass : public QObject
{
Q_OBJECT
Q_PROPERTY(IService* service READ service WRITE setService)
QTMVVM_INJECT(IService*, service)
public:
//...
}
Note
All properties that make use of interfaces must register the interfaces via QtMvvm::registerInterfaceConverter
See also
QTMVVM_INJECT_PROP, QtMvvm::registerInterfaceConverter, QtMvvm::ServiceRegistry

◆ QTMVVM_INJECT_PROP

#define QTMVVM_INJECT_PROP (   type,
  name,
  member 
)
Value:
Q_PROPERTY(type name MEMBER member) \
QTMVVM_INJECT(type, name)

Create a for injection marked property based on a member.

Parameters
typeThe type of the property to be created
nameThe name of the property to be created
memberThe name of the member variable to use for the property

This macro is a shortcut for QTMVVM_INJECT to create a property and mark it for injection in one step. The property is created by using a member variable. This means it will have no public member functions to access the property, only the property accessors itself.

Sample code for usage:

class MyClass : public QObject
{
Q_OBJECT
QTMVVM_INJECT_PROP(IService*, service, _service)
public:
//...
private:
IService* _service;
}
Note
All properties that make use of interfaces must register the interfaces via QtMvvm::registerInterfaceConverter
See also
QTMVVM_INJECT, QtMvvm::registerInterfaceConverter, QtMvvm::ServiceRegistry