Input Chinese in Qt5 program
Backgroud
- OS: Debian Buster x64
- Language: en_US.UTF-8
- Desktop: MATE Desktop 1.22.2
- Input: Fcitx v4.2.9.7
After switching to Debian Buster, I found that QT applications cannot switch input methods to Chinese, such as programs installed in wine (notepad / office 2007 / libreOffice / wps). But the other programs can switch input methods for Chinese input, such as Firefox / VIM / Leafpad, etc.
Solution
I have search it with Baidu/Google for a long time, basically add variables to specify fcitx or recompile fcitx-qt5.
And I use the third method to solve this problem.
One. Add environment variables
Add the following variables in .bashrc
/.xprofile
/.xinputrc
/.profile
or write a script.
1 | export GTK_IM_MODULE=fcitx |
Two. Compile fcitx-qt5 from source
The official repository of fcitx-qt5 in Linux is too old and is not compatible with QT5.6 and above. You need to recompile it in the new version of QT.
Note: Do not omit the following steps, otherwise some errors may occur during compilation.
1. Install dependencies
1 | :~$ sudo apt-get install cmake fcitx-libs-dev extra-cmake-modules |
2. Install QT5 and fcitx-qt5s’ source
Download and install Web - QT5 locally.
Here we download QT5.14.1 for linux 64-bits。
1 | :~$ wget http://download.qt.io/official_releases/qt/5.14/5.14.1/qt-opensource-linux-x64-5.14.1.run |
During the installation process, you first need to register on the QT website, and then you will encounter a check box. If you don’t know which one to install, install them all.
1 | :~$ git clone https://github.com/fcitx/fcitx-qt5 |
3. Start compiling
1 | :~$ export PATH="/home/root/Qt5.14.1/5.14.1/gcc_64/bin":$PATH |
Fortunately, we have compiled successfully, and here we need libfcitxplatforminputcontextplugin.so
.
If you get an error, please Google resolve it by yourself.
4. Overwrite the original module
1 | :~$ mv /usr/lib/x86_64-linux-gnu/qt5/plugins/platforminputcontexts/libfcitxplatforminputcontextplugin.so /usr/lib/x86_64-linux-gnu/qt5/plugins/platforminputcontexts/libfcitxplatforminputcontextplugin.so.old |
Three. Switch to Chinese locale
I accidentally changed the language variable in locale, then fcitx can be used normally in the QT program!
Take LibreOffice as an example:
1 | :~$ cat > office <<EOF |
I wrote a script, first set the locale environment variable to Chinese, then close the existing fcitx, and then reopen fcitx and libreoffice. At this time, you can enter Chinese in LibreOffice.
In order to practice my English, I don’t want to switch back to the Chinese locale. So I used the above method to write a script for the QT5 program.
Prefences:
- CSDN
- fcitx
- qt web