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)
Problem Description In the recent background serv...
Table of contents Preface What is Deno? Compariso...
Microsoft IIS IIS (Internet Information Server) i...
This article shares the specific code for the WeC...
One of our web projects has seen an increase in t...
introduction Let's start with our content. I ...
Sometimes we need to import some data from anothe...
Preface NFS (Network File System) means network f...
Preface MySQL is a relational database with stron...
A: Usually stored in the client. jwt, or JSON Web...
!DOCTYPE Specifies the Document Type Definition (...
What is an index? An index is a data structure th...
Vue parent component calls the function of the ch...
Introduction to void keyword First of all, the vo...
describe: When the Tabs component switches back a...