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