[Qt-interest] QDBusConnection::ExposeChildObjects

Thiago Macieira thiago at kde.org
Mon Sep 26 12:55:33 CEST 2011


On Monday, 26 de September de 2011 11:57:57 Stefan Majewsky wrote:
> I'm trying to implement an application that exposes a standardized
> DBus interface. The specification states that (using metasyntactic
> variables) the application must expose the "/org/someinterface" object
> path, which must implement the "org.someinterface.foo" and
> "org.someinterface.bar" interfaces.
> 
> I have the XML files for these interfaces, and have qdbusxml2cpp
> autogenerate adaptor classes for them. In the code, I want to keep the
> classes Foo and Bar implementing the interfaces separate. Both are
> constructed like this:
> 
> Foo::Foo(QObject* parent) : QObject(parent)
> {
>     new FooAdaptor(this);
>     QDBusConnection::registerObject(OBJECT_PATH, this);
> }
> 
> When I instantiate only Foo, it works fine (as in: shows up on the
> DBus correctly and stuff). But when I instantiate Bar, it won't show
> up. I think that's registerObject() not allowing two objects on the
> same path (sounds reasonable). However, I really want Foo and Bar to
> be separate classes, or it becomes a royal mess. So I tried to use the
> ExportChildObjects flag of registerObject(). Like this:

If you want two interfaces on the same object path, you need to create the 
adaptors on the same object. No way around.

A child object would appear as a child object path.

> void inside_main()
> {
>     QObject master;
>     new Foo(&master);
>     new Bar(&master);
>     QDBusConnection::registerObject(OBJECT_PATH, &master,
> QDBusConnection::ExportAdaptors |
> QDBusConnection::ExportChildObjects);
> }
> 
> (Of course the registerObject() call is gone from Foo's and Bar's
> ctors now.) But now only an empty object shows up on the DBus (i.e.
> qdbus only gives me the default Properties and Introspect interfaces).
> What am I doing wrong?

You forgot to give Foo and Bar names. You need to call setObjectName() on 
those two objects.

E.g.:
	Foo *f = new Foo(&master);
	f->setObjectName("foo");

This will cause it to appear under "/org/someinterface/foo".

-- 
Thiago Macieira - thiago (AT) macieira.info - thiago (AT) kde.org
   Software Architect - Intel Open Source Technology Center
      PGP/GPG: 0x6EF45358; fingerprint:
      E067 918B B660 DBD1 105C  966C 33F5 F005 6EF4 5358
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 190 bytes
Desc: This is a digitally signed message part.
Url : http://lists.qt-project.org/pipermail/qt-interest-old/attachments/20110926/d53f161b/attachment.bin 


More information about the Qt-interest-old mailing list