Difference between revisions of "Archive:Development/Architecture/KDE4/Starting Other Programs (zh CN)"

Jump to: navigation, search
Line 9: Line 9:
== KProcess ==
== KProcess ==
You want to use [http://api.kde.org/4.x-api/kdelibs-apidocs/kdecore/html/classKProcess.html KProcess] class if you need to start a new process which needs to be a child of your process, e.g. because you want to catch stdout/stderr or need to send it data via stdin. You should never use this to start other KDE applications (unless your application is a debugger :-)
只有在你要启动一个子进程的时候,才使用[http://api.kde.org/4.x-api/kdelibs-apidocs/kdecore/html/classKProcess.html KProcess]。这时候你要捕捉系统输出或者错误,或者由系输入的数据。这不是启动KDE应用程序的方法,除非你在调试。
== KToolInvocation::startServiceByDesktopPath ==
== KToolInvocation::startServiceByDesktopPath ==
[http://api.kde.org/4.x-api/kdelibs-apidocs/kdecore/html/classKToolInvocation.html KToolInvocation::startServiceByDesktopPath] is the preferred way to launch desktop (KDE/Gnome/X) applications or KDE services. The application/service must have a .desktop file, and you must know the name of that file. KToolInvocation asks the klauncher process, via DBUS, to start the program.  
建议用[http://api.kde.org/4.x-api/kdelibs-apidocs/kdecore/html/classKToolInvocation.html KToolInvocation::startServiceByDesktopPath]来启动桌面应用(KDE/Gnome/X)或者KDE服务。桌面应用或服务应又一个.desktop文件,你的知道这个文件名。 KToolInvocation经DBUS通知KLauncher进程开始应用程序。
=== Klauncher ===
=== Klauncher ===
Line 18: Line 18:
=== kdeinit ===  
=== kdeinit ===  
klauncher makes use of KDEinit for increased startup performance and lower memory usage. These benefits only apply to applications available as KDEinit loadable module (KLM).
== KRun ==
== KRun ==

Revision as of 13:15, 22 February 2009


Development/Architecture/KDE4/Starting Other Programs

KDE 架构 - 程序启动


fork + exec





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


Klauncher will wait until the application registers to DBUS if the desktop file specifies the X-DBUS-StartupType key. This allows to make DBUS calls to the application once startServiceByDesktopPath returns, without the risk of race conditions. Note that klauncher needs to know under which name the application will register to DBUS: by default that is assumed to be org.kde.binaryname, but you can configure this by setting X-DBUS-ServiceName in the .desktop file. If you don't, you will get an error from klauncher which will think the application failed to start, since the expected dbus name never showed up.




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.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V.Legal