PDA

View Full Version : QMetaObject list interfaces



golubevsv
12th September 2014, 09:20
Hi all. I am using QT meta object system for my app-specific interfaces like this:


class MyInterface {
// interface description here
}
Q_DECLARE_INTERFACE(MyInterface, "com.my-org.MyInterface/1.0")


class MyInterfaceImplementor: public QObject, public MyInterface {
Q_OBJECT
Q_INTERFACES(MyInterface)

// MyInterface implementation
}

auto pInstance = new MyInterfaceImplementor();


So, my pInstance have an metaObject(). How can i query this metaObject() for query list of interfaces, implemented on it? All interfaces have been registered using Q_DECLARE_INTERFACE.

anda_skoa
12th September 2014, 11:18
I am not sure there is currently a way to list this information.
As far as I know the only thing the macro does basically is to make MOC generate cast functions to that a pointer to the object can be qobject_cast'ed to the interfaces it has.

Cheers,
_

golubevsv
12th September 2014, 12:14
I'm study output of moc compiler and I've found, that my way is call qt_metacast on my object passing interface name (ex. "com.my-org.MyInterface") as parameter. If qt_metacast returns non-NULL value, so object implements this interface. Now a can not found way to list all interface names, that have been registered via Q_DECLARE_INTERFACE. Is it possible?

anda_skoa
12th September 2014, 16:20
As I said, not to my knowledge.

Cheers,
_

d_stranz
12th September 2014, 18:47
How can i query this metaObject() for query list of interfaces, implemented on it?

If these are all of your own objects (and interfaces), then you can implement your own lookup mechanism to determine the names of the interfaces each object implements. You can add another macro, for example:


REGISTER_INTERFACE(MyInterface, "com.my-org.MyInterface/1.0")

that inserts the QMetaObject::className() as a key into an application-level multi-map that associates the name with a list of interface names.

anda_skoa
13th September 2014, 11:17
Right, or by using Q_CLASSINFO()

Cheers,
_