Results 1 to 6 of 6

Thread: QMetaObject list interfaces

  1. #1
    Join Date
    Sep 2014
    Posts
    14
    Qt products
    Qt5
    Platforms
    Unix/X11 Windows

    Default QMetaObject list interfaces

    Hi all. I am using QT meta object system for my app-specific interfaces like this:

    Qt Code:
    1. class MyInterface {
    2. // interface description here
    3. }
    4. Q_DECLARE_INTERFACE(MyInterface, "com.my-org.MyInterface/1.0")
    5.  
    6.  
    7. class MyInterfaceImplementor: public QObject, public MyInterface {
    8. Q_OBJECT
    9. Q_INTERFACES(MyInterface)
    10.  
    11. // MyInterface implementation
    12. }
    13.  
    14. auto pInstance = new MyInterfaceImplementor();
    To copy to clipboard, switch view to plain text mode 

    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.

  2. #2
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: QMetaObject list interfaces

    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,
    _

  3. #3
    Join Date
    Sep 2014
    Posts
    14
    Qt products
    Qt5
    Platforms
    Unix/X11 Windows

    Default Re: QMetaObject list interfaces

    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?

  4. #4
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: QMetaObject list interfaces

    As I said, not to my knowledge.

    Cheers,
    _

  5. #5
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,233
    Thanks
    303
    Thanked 864 Times in 851 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: QMetaObject list interfaces

    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:

    Qt Code:
    1. REGISTER_INTERFACE(MyInterface, "com.my-org.MyInterface/1.0")
    To copy to clipboard, switch view to plain text mode 

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

  6. #6
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: QMetaObject list interfaces

    Right, or by using Q_CLASSINFO()

    Cheers,
    _

Similar Threads

  1. How to get list of physical network interfaces?
    By hitmaneidos in forum Qt Programming
    Replies: 2
    Last Post: 2nd February 2012, 02:17
  2. How to use Microsoft COM interfaces in QT?
    By luochen601 in forum Qt Programming
    Replies: 3
    Last Post: 31st May 2010, 04:22
  3. Qt Designer for web interfaces
    By rbp in forum Qt Tools
    Replies: 3
    Last Post: 14th October 2009, 02:01
  4. Polymorphism interfaces in C++
    By ComaWhite in forum General Programming
    Replies: 2
    Last Post: 1st July 2009, 12:38
  5. Plugin Interfaces
    By Paul Drummond in forum Qt Programming
    Replies: 1
    Last Post: 27th February 2006, 13:37

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.