C QT GUI app. using D-BUS and/or CLI direct messaging test

I'm writing a simple GUI QT application that is supposed to be able to send CLI commands to other active processes (in my case daemons ran by the base-system (pflogd, cron, sshd, etc.) and also to be able to receive messages from the same daemons back into my application. I understand there are pretty much two ways of doing this (please correct me if I'm wrong):

1. Sending CLI messages with the
Code:
system(<command line>); // not recommended

I tried using the system() function but I don't know how to get messages back into my app. Do I need to pipe the output of the process I want to call back into my own app. using the app's
Code:
main();
arguments?

For example, say I'd like to do ls -l and get all the output into a GUI table in my own application. What would be the best way to do that using the CLI method? I'm especially interested in a way to receive asynchronous messages. Take for example the whereis <application_name> command. It will take some time to process. How can I synchronize the response coming from whereis with my own app? Do I need to call this command on a separate thread and kill it once I get something back?

2. Using the dbus-daemon()

It is my understanding that most modern desktop environments use the dbus-daemon for IPC. I've noticed that QT has a dedicated object called QDBus, but I can't seem to fully understand how the dbus-daemon works. According to the manual there are two instances: a systemwide bus and a user-login-session bus.

According to the manual also, the systemwide bus is used for broadcasting system events. So, in theory I should be able to output system messages (e.g. usb device removal or addition - messages) into a C/C++ application straight from this instance of dbus-daemon, correct? Using the dbus-daemon, is there a way to send messages to already running processes, start new processes, and also receive messages back into another process (e.g. my application)?

I tried to launch dbus-daemon --session from an ssh connection to see how it works, but nothing happens. The cursor gets stuck. What am I missing?

edited: any suggestions or tutorials that can get me started would be very much appreciated
 
Back
Top