一.QT4
按照网上了说没有字库我添加了还是没用。最后折腾了半天,搞定了,分享一下。
1.第一步下载font_wenquanyi.rar可以是qpf也可以是ttf,网址
https://pan.baidu.com/s/1EaB6V9i_DQoKqsfT8_bWMg
或者安装freetype字体:
sudo apt-get install libfreetype6
2.将这个字库复制到QT的/lib/fonts下
3..在mainWindows w下添加
QTextCodec* codec = QTextCodec::codecForName("UTF-8");
QTextCodec::setCodecForLocale(codec);
QTextCodec::setCodecForCStrings(codec);
QTextCodec::setCodecForTr(codec);
1:apt-get install libfontconfig1-dev
2:apt-get install libfreetype6-dev
3: cd qt-everywhere-opensource-src-4.8.5/
4:./configure -fontconfig && make && make install
5:进入qt安装目录 ./qtconfig 配置QT的字体,把字体配置成sim sun
4.写text时,ui->button->setText(QString::fromUtf8("测试"));即可
二.QT5
这个就要感谢我的同事,经过他长时间的试验终于解决了。
1.下载ttf格式的字体以及设置
下载我这里就不多说了直接上设置代码,在main里加入
int id = QFontDatabase::addApplicationFont("/lib/fonts/WenQuanYi_Micro_Hei.ttf");
QString msyh = QFontDatabase::applicationFontFamilies(id).at(0);
QFont font(msyh, 10);
font.setPointSize(20);
a.setFont(font);
2.写text时,如果不是UTF-8格式的时候,ui->button->setText(QObject::trUtf8("测试"));
三、安装windows字体
1、第一步:从 Windows 系统下字体文件夹(C:\Windows\Fonts) ,拷贝如下文件到当前Ubuntu目录 /usr/share/fonts/windows-font
2、修改权限并更新字体缓存
sudo chmod -R 777 /usr/share/fonts/windows-font
cd /usr/share/fonts/windows-font
sudo mkfontscale
sudo mkfontdir
sudo fc-cache -fv
四、找不到libGL
sudo apt-get install libgl1-mesa-dev libglu1-mesa-dev
或者
方法一
locate libGL 找到GL库路径
sudo ln -s /usr/lib/x86_64-linux-gnu/mesa/libGL.so.1/usr/lib/libGL.so
五、Ubuntu16.04更新为清华源
cd /etc/apt
sudo cp source.list source.list.bak
sudo vi source.list
///将文件内容替换为
# deb cdrom:[Ubuntu 16.04 LTS _Xenial Xerus_ - Release amd64 (20160420.1)]/ xenial main restricted
deb http://mirrors.tuna.tsinghua.edu.cn/ubuntu/ xenial main restricted
deb http://mirrors.tuna.tsinghua.edu.cn/ubuntu/ xenial-updates main restricted
deb http://mirrors.tuna.tsinghua.edu.cn/ubuntu/ xenial universe
deb http://mirrors.tuna.tsinghua.edu.cn/ubuntu/ xenial-updates universe
deb http://mirrors.tuna.tsinghua.edu.cn/ubuntu/ xenial multiverse
deb http://mirrors.tuna.tsinghua.edu.cn/ubuntu/ xenial-updates multiverse
deb http://mirrors.tuna.tsinghua.edu.cn/ubuntu/ xenial-backports main restricted universe multiverse
deb http://mirrors.tuna.tsinghua.edu.cn/ubuntu/ xenial-security main restricted
deb http://mirrors.tuna.tsinghua.edu.cn/ubuntu/ xenial-security universe
deb http://mirrors.tuna.tsinghua.edu.cn/ubuntu/ xenial-security multiverse
sudo apt-get update
Ubuntu18.04 更新为清华源
##清华的源
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic main restricted universe multiverse
deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-updates main restricted universe multiverse
deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-updates main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-backports main restricted universe multiverse
deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-backports main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-security main restricted universe multiverse
deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-security main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-proposed main restricted universe multiverse
deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-proposed main restricted universe multiverse
Ubuntu20.04 更新为清华源
#清华源
# 默认注释了源码镜像以提高 apt update 速度,如有需要可自行取消注释
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal main restricted universe multiverse
# deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal-updates main restricted universe multiverse
# deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal-updates main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal-backports main restricted universe multiverse
# deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal-backports main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal-security main restricted universe multiverse
# deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal-security main restricted universe multiverse
# 预发布软件源,不建议启用
# deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal-proposed main restricted universe multiverse
# deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal-proposed main restricted universe multiverse
Ubuntu22.04 更新为清华源
# 默认注释了源码镜像以提高 apt update 速度,如有需要可自行取消注释
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ jammy main restricted universe multiverse
# deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ jammy main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ jammy-updates main restricted universe multiverse
# deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ jammy-updates main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ jammy-backports main restricted universe multiverse
# deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ jammy-backports main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ jammy-security main restricted universe multiverse
# deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ jammy-security main restricted universe multiverse
# 预发布软件源,不建议启用
# deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ jammy-proposed main restricted universe multiverse
# deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ jammy-proposed main restricted universe multiverse