Re: dbus example

Thiago Macieira <[email protected]>
Newsgroups gmane.comp.freedesktop.dbus
Message-ID <3197738.l6BvAJ61eA@tjmaciei-mobl1>
On terça-feira, 1 de agosto de 2017 00:53:56 PDT Yubin Ruan wrote:
> 2017-08-01 15:44 GMT+08:00 Thiago Macieira <[email protected]>:
> > Any C++ binding will work? Then I can give you examples using QtDBus.
> 
> Yes. But please offer a workable example. Many thanks!

A very simple client is:

	QDBusInterface iface("org.example.servicename", 
		"/org/example/object/path",
		"org.example.InterfaceName");
	QDBusPendingReply<int> reply = iface.asyncCall("Method", 1, 2, 3);
	reply.waitForFinished();	// blocks until finished
	if (reply.isError()) {
		// handle reply.error()
	} else {
		int value = reply;
		// use value
	}

This is not the way I recommend doing clients, though, since you can get the 
spelling of "Method" wrong or the types of the arguments (three ints in this 
case wrong too. First, note the blocking call to waitForFinished(). If 
possible, you should not block and just use the event loop to wait for the 
reply there -- use QDBusPendingCallWatcher.

Second, I recommend taking your interface definition's XML file and pass it 
through qdbusxml2cpp to create both the interface and the adaptor classes. The 
interface class you'll use in place of QDBusInterface above. It'll have a C++ 
method called "Method" that takes the correct parameter types and returns the 
right QDBusPendingReply type.

The adaptor class is for the server side. See QtDBus documentation and 
examples for more.

-- 
Thiago Macieira - thiago (AT) macieira.info - thiago (AT) kde.org
   Software Architect - Intel Open Source Technology Center

_______________________________________________
dbus mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dbus
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.