Background: I'm working on asset reporting related functions recently, and I need to support Chinese input. If the program is started with a normal shortcut, there is no problem. However, when upgrading or uninstalling and reinstalling, it is started with su usr -C XX.sh. It is impossible to obtain the user's environment variables when started under root. Let's start our adventure. . . Exploration: By comparing the environment variables of root and user through export printing, and searching for issues related to input methods under linux in google, I found the variable QT_IM_MODULE. Different systems may have ibus or fctix or other variables, etc. Solution: Because the program needs to be started manually by the user when it is installed for the first time, we need to add the code to get the value of QT_IM_MODULE under the current user, and then write it to a global file, and then get the value of this global variable in the hook script. In the startup script, just set export QT_IM_MODULE=XX. The code is shown below. The code has something to say: 1. Code that needs to be added to the program: //Add global Chinese input method environment variable QString qstrInputMethod = path; qstrInputMethod += "/.local/sdforcnos/sdforcnos.inputMethod"; char *pInputEnv = getenv("QT_IM_MODULE"); if(pInputEnv != NULL) { QString qstrCMD = QString("echo %1 > %2").arg(pInputEnv).arg(qstrInputMethod); system(qstrCMD.toStdString().c_str()); printf("---%s-----------QT_IM_MODULE=%s\n", qstrCMD.toStdString().c_str(), pInputEnv); } 2. Code required by the hook script: if [ -e "/home/${user}/.local/sdforcnos/sdforcnos.inputMethod" ];then inputEnv=`cat /home/${user}/.local/sdforcnos/sdforcnos.inputMethod` if [ ! -z "$inputEnv" ]; then export QT_IM_MODULE="$inputEnv" fi fi su $user -c "/usr/bin/startsd &" Summarize This is the end of this article about Chinese input method problems under Linux. For more relevant content about Chinese input method problems under Linux, please search for previous articles on 123WORDPRESS.COM or continue to browse the related articles below. I hope everyone will support 123WORDPRESS.COM in the future! You may also be interested in:
|
<<: Vue implements adding watermark to uploaded pictures
>>: Vue realizes adding watermark to uploaded pictures (upgraded version)
Preface In some cases, we only know the intranet ...
This article uses examples to illustrate the prin...
1. Backup source list The default source of Ubunt...
Let me share with you a creative opening realized...
Table of contents Overview 1. Download via URL 2....
Some time ago, I needed to use pip downloads freq...
After pressing Enter on the webpage, the form is a...
Table of contents Preface Check and uninstall Ope...
This article example shares the specific code of ...
Description of port availability detection when p...
CAST function In the previous article, we mention...
Preface The master-slave replication relationship...
1. pc-reset PC style initialization /* normalize....
As a technical novice, I am recording the process...
Table of contents 1. Through HBuilderX visual int...