PDA

View Full Version : How to autoRun the command "dbus-daemon --config-file=session.conf"?



to_guliang
8th July 2010, 02:45
hello,everyone
i use the QtDBus in my Qt4.6.2 application. Before run my application, it's necessary to run the DBus session process and the DBus session process must be runing untill my application exit.
I run the DBus session process by input "dbus-daemon --config-file = session.conf" in the hyperterminal at first.
Now I want the DBus session process could autorun in my application, i have tried two method but not succeed:
1. the "dbus-daemon.exe" and the "session.conf" are in the "DBusEssential"


system("/DBusEssential/dbus-daemon --config-file=/DBusEssential/session.conf");

the "system" excute the command, but it exit at once. My application need the DBus session process is always running.

2.
QProcess myProcess;
myProcess.start("/DBusEssential/dbus-daemon --config-file=/DBusEssential/session.conf");

I Know it's not correct to use like this, but i don't know the correct way.

May be the "session.conf" could write to the "config-file" of the "dbus-daemon.exe", and then "start " the "dbus-daemon.exe"? How to??

please help me. thanks very much.
regards for any advice!!!

nice295@gmail.com
8th July 2010, 05:28
How about this?

QProcess::startDetached("/DBusEssential/dbus-daemon --config-file=/DBusEssential/session.conf);

QProcess::startDetached() is a static member function and sill will be working after your process exit.

to_guliang
12th July 2010, 09:23
thanks.
your suggestion doesn't work. Maybe the program name should be "/DBusEssential/dbus-daemon.exe ", but the "--config-file" and the "session.conf" how to configure to the program???

i don't know how. waiting for replying....

wysota
12th July 2010, 10:13
Pass the arguments in a form of a string list as a second argument to startDetached().

to_guliang
13th July 2010, 07:24
Pass the arguments in a form of a string list as a second argument to startDetached().

thanks very much.

i tried what you said as following manner,
but it doesn't work.
At the same time, i have tried "QString program = "/DBusEssential/dbus-daemon.exe". It doesn't work.

could you tell me what's wrong in my code? Thanks a lot.


QString program = "/DBusEssential/dbus-daemon";
QStringList arguments;
arguments << "--config-file" << "=" << "/DBusEssential/session.conf";
QProcess::startDetached(program,arguments);

wysota
13th July 2010, 10:11
It seems to me "--config-file=/DBusEssential/session.conf" is a single argument and not three separate ones.

to_guliang
19th July 2010, 05:06
It seems to me "--config-file=/DBusEssential/session.conf" is a single argument and not three separate ones.

Putting the "--config-file=/DBusEssential/session.conf" in a single argument doesn't work........

wysota
19th July 2010, 12:38
Any details on how "doesn't work" occur?

ChrisW67
19th July 2010, 23:02
You haven't established whether the command you are trying to run works at all. If you type exactly this:

/DBusEssential/dbus-daemon --config-file=/DBusEssential/session.conf
into your terminal, with the same environment as the application will have, does it run? Does it give you meaningful errors if it doesn't?

to_guliang
26th July 2010, 04:37
Thanks to wysota and ChrisW67!!!!!!

i must say sorry . today i do as ChrisW67 says, it doesn't work in terminal. I remember that i have tried "/DBusEssential/dbus-daemon --config-file=/DBusEssential/session.conf" in my terminal and it works. the facts prove that i have misremember.

now, i copy the "dbus-daemon.exe" and "session.conf" to the project root directory, the effective code is follows:

QString program = "dbus-daemon.exe";
QStringList arguments;
arguments << "--config-file=session.conf";
QProcess::startDetached(program,arguments);

but now there is another problem, a terminal window named "d:\QtProject\dbus-chat\dbus-daemon.exe" will appear in my desktop. As you know, the client won't accept this window.
Maybe there is a better way to autorun the dbus-daemon.exe without the terminal window?

to_guliang
26th July 2010, 05:00
The following code will do the right thing. the "dbus-daemon.exe" will exit if the application exit:



QString program = "dbus-daemon.exe";
QStringList arguments;
arguments << "--config-file=session.conf";

QProcess myProcess;
myProcess.start(program, arguments);


Thanks to all!

ChrisW67
26th July 2010, 05:01
Be a little careful because the program's working directory may not be be same as the application executable's location: you might want to use QCoreApplication::applicationDirPath() to find dbus-daemon.

Regarding the console window:

Does using the DBus "--fork" option help?
Is "dbus-launch" of any use?
Does making the command equivalent to "cmd /c start /b dbus-daemon --config-file=session.conf" help?
Does capturing the program output stream help?