KTerminalLauncherJob Class

KTerminalLauncherJob starts a terminal application, either for the user to use interactively, or to execute a command. More...

Header: #include <KTerminalLauncherJob>
CMake: find_package(KF6 REQUIRED COMPONENTS KIO)
target_link_libraries(mytarget PRIVATE KIOGui)
Inherits: KJob

Public Functions

KTerminalLauncherJob(const QString &command, QObject *parent = nullptr)
virtual ~KTerminalLauncherJob() override
(since 6.17) bool prepare()
void setProcessEnvironment(const QProcessEnvironment &environment)
void setStartupId(const QByteArray &startupId)
void setWorkingDirectory(const QString &workingDirectory)

Reimplemented Public Functions

virtual void start() override

Detailed Description

It creates a startup notification and finishes it on success or on error (for the taskbar). It also emits an error message if necessary (e.g. "program not found").

The job finishes when the application is successfully started. For error handling, either connect to the result() signal, or for a simple messagebox on error, you can do

job->setUiDelegate(new KDialogJobUiDelegate(KJobUiDelegate::AutoHandlingEnabled, this));

Member Function Documentation

[explicit] KTerminalLauncherJob::KTerminalLauncherJob(const QString &command, QObject *parent = nullptr)

Creates a KTerminalLauncherJob.

command the command to execute in a terminal, can be empty.

parent the parent QObject

[override virtual noexcept] KTerminalLauncherJob::~KTerminalLauncherJob()

Destructor

Note that jobs auto-delete themselves after emitting result

[since 6.17] bool KTerminalLauncherJob::prepare()

Checks whether the command to launch a terminal can be constructed and sets it.

The start() function calls this internally, so you only need to call prepare() directly if you want to validate the command separately from actually starting the terminal.

This is useful if you want to avoid calling start() just to catch an error, for example to conditionally show or hide a GUI element depending on whether launching a terminal is likely to succeed.

Returns true if a launch command could be constructed, false otherwise.

This function was introduced in 6.17.

See also start().

void KTerminalLauncherJob::setProcessEnvironment(const QProcessEnvironment &environment)

Can be used to pass environment variables to the child process.

environment set of environment variables to pass to the child process

See also QProcessEnvironment.

void KTerminalLauncherJob::setStartupId(const QByteArray &startupId)

Sets the platform-specific startup id of the command launch.

startupId startup id, if any (otherwise "").

For X11, this would be the id for the Startup Notification protocol.

For Wayland, this would be the token for the XDG Activation protocol.

void KTerminalLauncherJob::setWorkingDirectory(const QString &workingDirectory)

Sets the working directory from which to run the command.

workingDirectory path of a local directory

[override virtual] void KTerminalLauncherJob::start()

Reimplements: KJob::start().

Starts the job. You must call this, after having called all the necessary setters.