PDA

View Full Version : DBus and IPC



DrDonut
17th March 2008, 14:09
Hi all,

Somehow I need to send data (some integers) between two running processes. My question is how to do that using qt or some other c++ code.

I've seen some suggestions around the web, there seem to be a number of ways to solve this problem, but I haven't found a good one yet.

It seems that using DBus is a good way to achive this, but I've got some problems with that. The first thing is that it needs to run on windows xp, and I'm not completely sure if that is supported in DBus.

Second problem is that there are some exaples that have code snippets around, but none with complete code. Which means that I don't know what the correct syntax is and that I miss some basic things like which header files to include and stuff like that.

I've found an example on someones blog about sending messages, it seems to be a really good example, but it's written in C# and i'm using C++ and I don't know how to "translate" that.

So my question is: does annyone have an example of how to achieve this inter process communication using qt 4.3 under windows xp?

Thanks in advance!

codeslicer
18th March 2008, 01:33
I faced a similar problem when I needed to make my application single-instance without having access to the QtSingleApplication class. What you can do is use QSettings, and store information there. Be sure to call the QSettings::sync() member to have Qt save changes to the hard drive, otherwise the other application won't be able to read it.

The way I did my single-instance application is to have a QTimer with a slot to update the QSettings with the current time every 20 seconds, and then when the application starts up have it check the time in the QSettings and the current time, and see if they are 20 seconds apart or not(Less just in case it's not atomic).

Anyways, hope this helps!

DrDonut
18th March 2008, 09:05
Hi, first of all, thanks for your reply, but I think I have to pass on this one.

If this "semi-realtime" system is used, wouldn't it be easier/faster to write this to a specified file, which the 2nd program can read?

Yesterday I looked at using shared memory to send data between the processes, but it turns out that it's only supported in qt version 4.4 which is a beta release and I'd better like to use stable releases. Today however, I found a package which enables shared memory in qt 4.3, so I guess I try that one, or the one with the files.
[url]http://trolltech.com/products/qt/addon/solutions/catalog/4/Utilities/qtsharedmemory/[\url]

But once again, thanks for your reply.

Edit: I think I'd better read first, this package is only available for commercial licens holders:crying:

codeslicer
22nd March 2008, 23:42
QSettings is better than writing to a file, as it uses rather obscure places to store its data. On Windows it uses the registry, on Linux a hidden file, and in Mac on some preferences folder. Although writing to a hard drive is certainly not atomic, you can rest assured that it is still very fast.

Make sure when using QSettings that you specify the application and organization name to be the same for both programs, so that they can each read each others settings.