Archive:Development/Architecture/KDE4/Starting Other Programs (zh CN)

Revision as of 14:20, 22 February 2009 by Hualiang.miao (Talk | contribs)

Jump to: navigation, search

Development/Architecture/KDE4/Starting Other Programs

KDE 架构 - 程序启动


fork + exec





建议用KToolInvocation::startServiceByDesktopPath来启动桌面应用(KDE/Gnome/X)或者KDE服务。桌面应用或服务应又一个.desktop文件,你的知道这个文件名。 KToolInvocation经DBUS通知KLauncher进程开始应用程序。


如果.desktop文件指定了X-DBUS-StartupType键,那KLauncher将一直等到应用程序注册到DBUS上。一旦startServiceByDesktopPath返回,DBUS就会对应用程序调用起来 而不必担心竞争问题。注意:KLauncher需要知道应用程序使用哪个名字在DBUS注册的,通常,他是org.kde.binaryname, 但你也可以在.desktop文件里设置X-DBUS-ServiceName值。如果你不这么做,KLauncher会抛出一个错误,说这个应用程序启动不了,因为所期望的DBUS名字就没出现过。




Generic way to open documents/applications/shell commands. Uses startServiceByDesktopPath where applicable. Offers the additional benefit of startup-notification.
KRun can start any application, from the binary or the desktop file, it will determine the mimetype of a file before running the preferred handler for it, and it can also start shell commands. This makes KRun the recommended way to run another program in KDE.


KToolInvocation::invokeBrowser launches a web browser. The difference with using the more generic KRun on the webpage URL is that KRun has to determine the mimetype of the URL first (which, for HTTP, involves starting a download to read the headers), so if you know that the URL is an HTML webpage, use invokeBrowser, it will be faster.

更多内容: the problem with KRun for webpages is that it delays the appearance of the browser window, and if the user's preferred browser is a non-kde application like firefox then it has to start a second download while konqueror which can reuse the kioslave started by KRun. On the other hand if the URL might be an image or anything else than html, then KRun is the right solution, so that the right application is started.

Content is available under Creative Commons License SA 4.0 unless otherwise noted.