QProcess language
-
-
@sonichy Try to set process environment to the environment of your app:
-
QProcess just launches the executable and, as documented,
By default, the child process will have a copy of the current process environment variables that exist at the time the start() function is called.
The normal scenario starts from the current environment by calling QProcessEnvironment::systemEnvironment() and then proceeds to adding, changing, or removing specific variables. The resulting variable roster can then be applied to a QProcess with setProcessEnvironment().
Since you took systemEnvironment() and did not modify anything in the environment, you passed to the child process the environment it would have had by default. You obtained the same behaviour. Not "Useless", but "as directed."
x-terminal-emulator
is just a link, to a link, to an executable on my system. Exactly what environmental factor your terminal relies on for UI language determination depends on what terminal program is ultimately executed. Where does it point on yours?How your Qt executable is launched will govern what its initial and thus default child environment will be. How is your application launched? Was in launched by a user double-click in some desktop environment, for a script, a system daemon, ...?
-
@ChrisW67 said in QProcess language:
Since you took systemEnvironment() and did not modify anything in the environment, you passed to the child process the environment it would have had by default.
Hi Chris. I find this a bit misleading, as phrased. "By default", i.e. if the child process does not call[EDIT: I was wrong here, see @ChrisW67's response below.]setProcessEnvironment()
, it receives the calling process's environment, not the system one.process->start(); // receives caller's environment process->setProcessEnvironment(QProcessEnvironment::systemEnvironment()); process->start(); // receives system environment
@sonichy
If neither of these results in your x-terminal-emulator having the desired language then you need (presumably) to find environment variable(s) which it uses to determine its language and set those in a (copied) environment correctly before callingprocess->start()
. Or whatever it requires to control its language.Otherwise please answer @ChrisW67's questions. As he points out, precisely what
x-terminal-emulator
invokes con be configured/vary from Linux distro to distro. If whatever it ultimately runs does not provide a way to specify language, perhaps on the command line or via an environment variable, then you have to live with that. -
@JonB To quote the QProcessEnvironment::systemEnvironment() docs, "The systemEnvironment function returns the environment of the calling process." The older alternative, QProcess::systemEnvironment(), is similar. If the calling process modifies its own environment before this call then that will be reflected in the return value of these functions.
The child process will inherit either the parent process environment at the time of launch (the default behaviour) or whatever the parent process passes to setProcessEnvironment(). Calling setProcessEnvironment() with an unmodified version of systemEnvironment()'s return immediately before launch is effectively a no-op. Your options are equivalent.
-
@ChrisW67 said in QProcess language:
"The systemEnvironment function returns the environment of the calling process."
I stand corrected, and totally apologise. I did not even look this up :( I assumed with a name like that it returned some default system-wide, "neutral" environment not related to the calling process. Which perhaps I should have thought about an bit, as under Linux (where I know what I am doing) I am not sure here is any such thing! I intended only to clarify your wording, I was wrong, that paragraph should be ignored :(
-
S sonichy has marked this topic as solved