Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. QProcess language
QtWS25 Last Chance

QProcess language

Scheduled Pinned Locked Moved Solved General and Desktop
10 Posts 4 Posters 314 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • sonichyS Offline
    sonichyS Offline
    sonichy
    wrote on last edited by
    #1
    QProcess *process = new QProcess;
    process->setWorkingDirectory(path);
    QString cmd = "x-terminal-emulator";
    process->setProgram(cmd);
    process->start();
    

    The terminal is english, not the Linux system language.
    QProcess start other application is english too.

    https://github.com/sonichy

    jsulmJ 1 Reply Last reply
    0
    • sonichyS sonichy
      QProcess *process = new QProcess;
      process->setWorkingDirectory(path);
      QString cmd = "x-terminal-emulator";
      process->setProgram(cmd);
      process->start();
      

      The terminal is english, not the Linux system language.
      QProcess start other application is english too.

      jsulmJ Offline
      jsulmJ Offline
      jsulm
      Lifetime Qt Champion
      wrote on last edited by
      #2

      @sonichy Try to set process environment to the environment of your app:

      • https://doc.qt.io/qt-6/qprocess.html#setProcessEnvironment
      • https://doc.qt.io/qt-6/qprocessenvironment.html#systemEnvironment

      https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      3
      • sonichyS Offline
        sonichyS Offline
        sonichy
        wrote on last edited by sonichy
        #3

        Useless

        process.setProcessEnvironment(QProcessEnvironment::systemEnvironment());
        

        https://github.com/sonichy

        1 Reply Last reply
        0
        • C Offline
          C Offline
          ChrisW67
          wrote on last edited by ChrisW67
          #4

          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, ...?

          JonBJ 1 Reply Last reply
          3
          • C ChrisW67

            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, ...?

            JonBJ Offline
            JonBJ Offline
            JonB
            wrote on last edited by JonB
            #5

            @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 setProcessEnvironment(), it receives the calling process's environment, not the system one. [EDIT: I was wrong here, see @ChrisW67's response below.]

            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 calling process->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.

            1 Reply Last reply
            1
            • C Offline
              C Offline
              ChrisW67
              wrote on last edited by
              #6

              @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.

              JonBJ 1 Reply Last reply
              3
              • C ChrisW67

                @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.

                JonBJ Offline
                JonBJ Offline
                JonB
                wrote on last edited by JonB
                #7

                @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 :(

                1 Reply Last reply
                0
                • C Offline
                  C Offline
                  ChrisW67
                  wrote on last edited by
                  #8

                  I had to do a double-take also.

                  1 Reply Last reply
                  1
                  • sonichyS Offline
                    sonichyS Offline
                    sonichy
                    wrote on last edited by
                    #9

                    I found the key !
                    Even QProcess without setProcessEnvironment.
                    Debug in Qt Creator, it is English.
                    Exec app in file browser, it is locale language!

                    https://github.com/sonichy

                    JonBJ 1 Reply Last reply
                    0
                    • sonichyS sonichy has marked this topic as solved on
                    • sonichyS sonichy

                      I found the key !
                      Even QProcess without setProcessEnvironment.
                      Debug in Qt Creator, it is English.
                      Exec app in file browser, it is locale language!

                      JonBJ Offline
                      JonBJ Offline
                      JonB
                      wrote on last edited by
                      #10

                      @sonichy
                      You perhaps ought make your Creator environment mirror your target deployment/run environment.
                      QProcess is not doing anything special, process inherits environment of how/where Qt program is running.

                      1 Reply Last reply
                      0

                      • Login

                      • Login or register to search.
                      • First post
                        Last post
                      0
                      • Categories
                      • Recent
                      • Tags
                      • Popular
                      • Users
                      • Groups
                      • Search
                      • Get Qt Extensions
                      • Unsolved