WSL Chinese cannot be displayed

Problem Description

Today, I used Qt Creator installed in WSL Ubuntu 20.04 to open the project, and found that the Chinese in the comments could not be displayed. as the picture shows:
insert image description here

Cause Analysis

At first, I mistakenly thought that there was a coding problem in qt creator, but after testing, I found that Chinese characters cannot be displayed under WSL. Because WSL does not have Chinese fonts, Chinese characters are displayed in small boxes, and there is no corresponding font library, so the corresponding texture cannot be rendered.

solution

Due to WSL's unique advantages of dual-system file sharing, we directly use the fonts that come with Windows (you can also install the font library yourself).

sudo ln -s /mnt/c/Windows/Fonts /usr/share/fonts/font

Scan the font directory and generate a cache of font information

fc-cache -fv

insert image description here

That's it, Chinese can be displayed normally!

Guess you like

Origin blog.csdn.net/bmseven/article/details/129372368