Results 1 to 5 of 5

Thread: Qt interface based programming

  1. #1
    Join Date
    Jun 2009
    Posts
    4
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Qt interface based programming

    Hi,

    I am new to Qt and developing a product where I would like to use interface based programming. Essentially, this means mimicking Microsoft COM (i.e. all interfaces are derived from IUnknown).

    I am not really 100% familiar with the Qt object model so I am not sure I can do this. With com usually the first interface implemented is IUnknown, but I notice that with Qt I have to subclass from QObject first and then I can list the other classes/interfaces I am implementing.

    Anyone have any experiences or suggestions on how to proceed?

    Regards.

  2. #2
    Join Date
    Jun 2008
    Location
    Germany/Belarus/Sweden
    Posts
    53
    Thanks
    3
    Thanked 1 Time in 1 Post
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: Qt interface based programming


  3. #3
    Join Date
    Jun 2009
    Posts
    4
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Qt interface based programming

    Hi,

    ActiveQt is only supported on Windows. I am trying to mimick the functionality in a portable way. For this really I just need to implement IUnknown and follow com programming principles. I don't need the com infrastructure as I have only a couple of DLL's and I am writing a special function that uses DllGetClassObject to fetch the appropriate interface.

    The problem I am coming across is that if I implement IUnknown as the first interface I get compile errors. I can only fix this by putting QObject as the first class in the inheritance hierarchy.

    e.g.

    class CMyComponent : public IMyComponent, public QObject {
    Q_OBJECT
    ...

    gives compile errors

    BUT,

    class CMyComponent : public QObject, public IMyComponent {
    Q_OBJECT

    is OK. But as far as I know, in com world this is not the way to do it.

    Regards.

  4. #4
    Join Date
    May 2009
    Posts
    62
    Thanks
    2
    Thanked 16 Times in 15 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Qt interface based programming

    The Qt plugin system allows you to define interfaces using Q_DECLARE_INTERFACE and later extract interfaces from a QObject using qobject_cast. Here is a good example. You can leave the plugin loading stuff away and link everything statically.

    Maybe this is what you are looking for?

  5. #5
    Join Date
    Jun 2009
    Posts
    4
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Qt interface based programming

    Hi,

    Thanks for that suggesstion. I did look into using plugins instead but gave up the idea because you can only have 1 plugin per dll, I didn't want to statically link them to the main application as I want to be able to update the interfaces without updating the main app (via a software update service).

    I wonder if the following would work:-

    1. Declare all interfaces as plugins in a single dll.
    2. statically import them in the same dll, and then use dllgetclassobject with qobject_cast to get the interfaces.

    Regards.

Similar Threads

  1. (ActiveQt) Invoking interface from COM object
    By mridulgandhi in forum Qt Programming
    Replies: 4
    Last Post: 11th October 2009, 20:29
  2. Replies: 12
    Last Post: 22nd March 2009, 11:22
  3. User Interface with QTableView
    By Brandybuck in forum Qt Programming
    Replies: 1
    Last Post: 22nd March 2006, 23:24
  4. Qt interface running extremely slowly...
    By jazztpt in forum Qt Programming
    Replies: 1
    Last Post: 4th February 2006, 11:12

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.