ubuntu Qt Creator不能输入中文

ubuntu Qt Creator不能输入中文

解决方式为下面的脚本,如果你的Qt是安装在根目录下,那么需要加sudo,如果不是,直接运行即可

sudo bash ChineseInputForQt-v1.1.sh

#  或者

bash ChineseInputForQt-v1.1.sh

脚本内容为:

#! /bin/bash
#------------------------------------------------------------------------------
# Filename:    chineseForQt.sh
# Usage:       ./chineseForQt.sh
# Version:     1.0
# Date:        2017-45-04
# Author:      vincent
# Email:       N/A
# Description: N/A
# Notes:       N/A
# 解决Qt中不能输入中文的问题
# 支持ubuntu 16.04,ubuntu 18.04,linux mint
#-------------------------------------------------------------------------------
# 查找Qt的安装目录

installPath=$(ls /usr/share/applications/ | grep -x "DigiaQt-qtcreator-community.desktop" )

ExecStr=""

if [ -z "$installPath" ]
then
    installPath=$(ls /usr/share/applications/ | grep -x "DigiaQt-qtcreator-enterprise.desktop")
	if [ -z "$installPath" ]
    then
				installPath=$(ls /usr/share/ubuntu/applications/ | grep -x "DigiaQt-qtcreator-enterprise.desktop")
				if [ -z "$installPath" ]
				then
					echo "Qt Creator is not installed !!!"
					exit 1
				else
					ExecStr=$(grep Exec /usr/share/ubuntu/applications/$installPath)
				fi
    else
		ExecStr=$(grep Exec /usr/share/applications/$installPath)
	fi
fi



ExecStr=$(echo ${ExecStr#*=})
ExecStr=$(echo ${ExecStr%/Tools*})
installPath=$ExecStr

declare USER=$(who | awk '{print $1}')
declare QT_VERSION=$(echo ${installPath#*Qt})

folderName=$(echo -e "${QT_VERSION%.*}") # 去除数字  如5.9.0去除 .0

folderArray=($(ls $installPath))

for(( i=0; i < ${#folderArray[@]}; i++ ))
do
	if [[ ${folderArray[$i]} == $folderName* ]]
	then
		folderName=${folderArray[$i]}
		break
	fi
done

declare libName="libfcitxplatforminputcontextplugin.so"
declare sourceFilePath="/usr/lib/x86_64-linux-gnu/qt5/plugins/platforminputcontexts/$libName"
declare destFolderPath="$installPath/Tools/QtCreator/lib/Qt/plugins/platforminputcontexts/"
declare dstFolderAnotherPath="$installPath/$folderName/gcc_64/plugins/platforminputcontexts/"

outputMsg()
{
	if [ $1 -ne 0 ]
	then
		echo "unsuccessful !!"
		exit 1
	fi
}

#sudo -s
sudo apt-get install -y fcitx-libs-qt5 > /dev/null

sudo cp $sourceFilePath $destFolderPath
outputMsg $?
sudo chown $USER:$USER ${destFolderPath}$libName
outputMsg $?
chmod 777 ${destFolderPath}$libName
outputMsg $?

sudo cp $sourceFilePath $dstFolderAnotherPath
outputMsg $?
sudo chown $USER:$USER ${dstFolderAnotherPath}$libName
outputMsg $?
chmod 777 ${dstFolderAnotherPath}$libName
outputMsg $?

echo "Successful! You can do it!"


发布了145 篇原创文章 · 获赞 357 · 访问量 44万+

猜你喜欢

转载自blog.csdn.net/wf19930209/article/details/103568365