QFontDatabase::addApplicationFont 一直返回-1问题

int fontId = QFontDatabase::addApplicationFont(qApp->applicationDirPath() + "/Styles/fontawesome-webfont.ttf"); QString fontName = QFontDatabase::applicationFontFamilies(fontId).at(0); ...
摘要由CSDN通过智能技术生成
    int fontId = QFontDatabase::addApplicationFont(qApp->applicationDirPath() + "/Styles/fontawesome-webfont.ttf");
    QString fontName = QFontDatabase::applicationFontFamilies(fontId).at(0);
    iconFont = QFont(fontName);

       在Linux平台测试发现程序异常退出,果断进入调试模式查看堆栈信息。问题出在applicationFontFamilies的at(0)索引越界。

       打断点发现QFontDatabase::addApplicationFont返回-1,导致程序异常。代码在别的虚拟机上可以成功运行。一开始以为路径没有获取成功,打印 qApp->applicationDirPath(),发现并不是路径问题。

按下F1查看"addApplicationFont"方法帮助文档。

       Loads the font from the file specified by fileName and makes it available to the application. An ID is returned that can be used to remove the font again with removeApplicationFont() or to retrieve the list of family names contained in the font.
The function returns -1 if the font could not be loaded.
Currently only TrueType fonts, TrueType font collecti

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 8
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 8
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值